How to connect to WSDL service using Binding Url in .Net - c#

I have been provided a Web Service which i need to consume in my MVC application .
The user has provided
WSDL URL :
http://abc.xyz.nirp.com:50000/dir/wsdl?p=ic/310c503c873138a884ddd3ee4a5738e6
Binding Url:
http://abc123.ad.xyx.com:50000/XISOAPAdapter/MessageServlet?senderParty=&senderService=BS_HARMONY_D&receiverParty=&receiverService=&interface=ABC_OS&interfaceNamespace=http%3A%2F%2Fabc.com%2Fhcm%2Fabc
I am able to add a service reference using the WSDL URL using SOAP credential but i also need to add these in the web configs and app configs which i am not able to understand where to put .
Pointers on how to use this Binding Url and put it in Web Config and App Config which be really helpful for me.

Check your web.config. After adding a service reference visual studio adds the endpoint in your web.config. You probably have a section like that:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="DefaultServiceEndpoint">
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="ADDRESS_HERE"
binding="wsHttpBinding" bindingConfiguration="DefaultServiceEndpoint"
contract="ServiceReference1.SOME_CLASS" name="DefaultServiceEndpoint" />
</client>
</system.serviceModel>
You can change the address here.

Related

Debug local WCF service with Basic Authentication always returns 401 - Unauthorized

I have a problem accessing a .Net WCF Service that uses Basic authentication. The server's web.config file has the service configured as such:
<services>
<service behaviorConfiguration="serviceBehavior" name="api.GlobalService">
<endpoint address="" behaviorConfiguration="restBehavior" binding="basicHttpBinding"
bindingConfiguration="Basic" contract="api.IGlobalService" />
</service>
</services>
with the binding:
<bindings>
<basicHttpBinding>
<binding name="Basic">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
In my IIS Express config file I enabled basic authentication as such:
<basicAuthentication enabled="true" />
I am running it in debug mode, on localhost, and I don't want a custom basic authentication, I want it to authenticate against Windows credentials. I access the server directly, from the browser, and enter my windows credentials when prompted, or from Postman using basic authentication and credentials, however I always get a 401. I am not authorized to access a server I run on my own machine with my own credentials. Any help on what I'm doing wrong?
You can try the following, in the application that consumes the WCF Service
WCFServiececlient.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
WCFServiececlient.ChannelFactory.Credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;

Getting "No connection could be made because the target machine actively refused it" error while calling HTTPS SOAP service from C# Windows Service

There is external SOAP API which supports requests over HTTPS only.
I am having Windows Service written in C# and calling this web service.
Below is the configuration on Windows Service's config -
<system.serviceModel>
<client>
<endpoint address="https://myExtAPI.com/api_1234/service.asmx"
binding="basicHttpBinding" bindingConfiguration="myExtAPI"
contract="myExtAPI" name="myExtAPI" />
</client>
<bindings>
<basicHttpBinding>
<binding name="myExtAPI">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
When call is made to API method I am getting this error - "No connection could be made because the target machine actively refused it".
I have written another web application. With same configuration, I am able to make successful call to API method.
UPDATE: Windows Service is running under Network Service account.
What am I missing? Any suggestions?
Thanks in advance.

Error connecting to asmx webservice on silverlight

i'm trying to connect a silverlight 4 application with an asmx webservice, but i'm getting an "InvalidOperationException" when trying to do so.
The problem occurs on the first line of this function
private void AskWebService() {
WSCalledSoapClient client = new WSCalledSoapClient();
client.AskThisCompleted += new EventHandler<AskThisCompletedEventArgs>(client_AskThisCompleted);
client.AskThisAsync("the answer to life, universe and everything");
}
The error of the exception should translate something like this (haven't found the english version of it)
element 'message' not recognized on the service reference configuration. Note that only a subset of the Windows Communication Foundation configuration functionality is available in Silverlight.
Details of the webservice:
Is published outside the silverlight project
Files clientaccesspolicy.xml and crossdomain.xml are in place
Details of the Silverlight App
SL version is 4.0, .net framework is also 4.0
Given the same config and same treatment (i.e. steps to import the webservice, code used to call the webservice), the call to the webservice works without problem on a new silverlight application that contains only a button and a textblock
The app uses others webservices, but only one is giving problem.
Update:
Here is the ServiceReferences.ClientConfig
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="WSCalledSoap" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://myip:someport/WSCalled.asmx"
binding="basicHttpBinding" bindingConfiguration="WSCalledSoap"
contract="SrvWSCalled.WSCalledSoap" name="WSCalledSoap" />
</client>
</system.serviceModel>
</configuration>
Any help will be appreciated.
Thanks.

WCF: Cannot find endpoint reference

I am working on a SharePoint 2013 webpart and a label on the webpart needs to communicate with a SQL Server data table using WCF. I have created the WCF interface and main class, and have also invoked the service in my Visual webpart like this:
protected void Page_Load(object sender, EventArgs e)
{
WcfServiceReference1.Service1Client client = new WcfServiceReference1.Service1Client();
CustomerNameLbl.Text = client.GetCustomerName(ProjectIDDescLbl.Text);
}
Where WcfServiceReference1 is the added WCF service reference and a customer label text is being changed depending on the project number label. The project builds and deploys fine but when I add the webpart, I get this error: Could not find default endpoint element that references contract 'WcfServiceReference1.IService1' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
My app.config file is this:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://as-sv-dev02:2345/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="WcfServiceReference1.IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
And web.config file (for SharePoint) is this:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://as-sv-dev02:2345/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="WcfServiceReference1.IService1"
name="BasicHttpBinding_IService1" />
</client>
Can anyone guide me on how to resolve this? Am I going wrong somewhere?
After a lot of research, I found out that there was some problem with SharePoint which I don't really understand. Thankfully, in time, I chose not to go the SharePoint way and instead work with a simple .aspx page and that would resolve the issue. Just unhappy with Microsoft not offering as much support on such common issues.
I had the same problem and I found this link.
http://social.technet.microsoft.com/Forums/en-US/dea0763d-d6ea-4659-8ef0-8275514d066a/sp2010-consuming-web-service-in-visual-web-part?forum=sharepointdevelopmentprevious
I did it and worked fine. The problem is the deploy does not copy the service model configuration from the Visual Studio' app.config to the IIS's web.config.
I hope helps.
Best Regards.
Your client endpoint does not seem to have a default configuration (name="" or nameless). Try using:
WcfServiceReference1.Service1Client client = new WcfServiceReference1.Service1Client("BasicHttpBinding_IService1");

BasicHttpBinding and MessageVersion.None

How to configure XML web services client to use MessageVersion.Soap11WSAddressing10 for header namespaces. Currently it uses MessageVersion.None namespace, without me able to change it.
You need to do this using a custom WCF binding:
<system.serviceModel>
<bindings>
<customBinding>
<binding name="Soap11Addr10">
<textMessageEncoding messageVersion="Soap11WSAddressing10" />
<httpTransport/>
</binding>
</customBinding>
</bindings>
and then reference that custom binding (by name) in your service endpoint:
<services>
<service name="YourAssembly.YourService">
<endpoint name="test"
address=""
binding="customBinding"
bindingConfiguration="Soap11Addr10"
contract="YourAssembly.IYourService" />
</service>
</services>
</system.serviceModel>
If you want to use this from a client, you also need to copy the custom binding configuration to the client's app.config or web.config and reference it there, of course (using Add Service Reference in Visual Studio will do this for you).

Categories

Resources