C# SOAP WebService: HTTPS endpoint configuration - c#

In a C# service i must add a Web Service reference for calling some metods.
The testing URL use an HTTPS protocol, so I'm try to edit my endpoint to call new address:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="fooSoap" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://x.x.x.x/WS_Foo/Foo.asmx"
binding="basicHttpBinding" bindingConfiguration="fooSoap"
contract="WSFooReferences.fooSoap" name="fooSoap" />
</client>
</system.serviceModel>
And so, I'm trying to call my method in c#:
WSFooReferences.fooSoapClient fooWS = new WSFooReferences.fooSoapClient();
int iRetCode = fooWS.Ping("ID12345");
But I've this error:
The provided URI scheme 'http' is invalid; expected 'https'
How I can edit my endpoint configuration fot this case?
T'ks!

Related

Programmatically define the Endpoint and Binding

Warping the call of a web service in a Class Library, I had to past the endpoint definition from app.config to other project that was using the Library.
In order to get rid of that I try to translate my app.config setting into explicit in order to pass Binding and Endpoint definition to the ClientBase.
var client = new myServiceClient(customBinding, custonEndpoint);
I'm looking for a way to translate system.serviceModel definition into code.
And the simpliest definition is giving me issue. For example with the following configuration:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_MyService" />
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://address:port/Foo/Services/MyService"
binding="netTcpBinding" bindingConfiguration="NetTcpBinding_MyService"
contract="MyService.MyService" name="NetTcpBinding_MyService">
<identity>
<userPrincipalName value="FooBar#SecondLevel.TopLevel" />
</identity>
</endpoint>
</client>
</system.serviceModel>
I find no property that match those parameter in NetTcpBinding neither in the Security property:
var endPoint = new EndpointAddress(__EndPoint);
var binding = new NetTcpBinding();
binding.Name = "";
Resulting in an error SSPI.

"There was no endpoint listening " This is often caused by an incorrect address or SOAP action

I have created the wcf service. I added the service using "add service refence" in vs2017.
after adding the service i am trying to access using below function (c#)
List<ProductData> data = new List<ProductData>();
ServiceReferenceIHS.PriceClient ns = new ServiceReferenceIHS.PriceClient();
data = ns.GetPricesData(clientName, password, lstISHCode.ToArray(), Startdate, EndDate).ToList();
I am providing the values to GetPricesData method.
below is the exception message.
There was no endpoint listening at http://localhost:8080/Test.svc that could accept the message.
This is often caused by an incorrect address or SOAP action.
See InnerException, if present, for more details.
The inner exception is Unable to connect to the remote server
this is the appconfig configuration.
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IPrice" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8080/Test.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IPrice"
contract="ServiceReferenceIHS.IPrice" name="BasicHttpBinding_IPrice" />
</client>
</system.serviceModel>
what is wrong in my code.

BasicHttpBinding from app.config inaccessible in code

I have several web services that I am connecting to from a Visual Studio C# project using service references. Two of the service references were created and work without a problem, and one of them took quite a lot of effort to get imported, and now seems to not be working.
I believe the problem lies in the app.config file since it is getting a "Could not find endpoint element" error when I try to create the client.
Here is the app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="RateQuoteSoap">
<security mode="Transport" />
</binding>
<binding name="RateQuoteSoap1" />
<binding name="QuoteSoap" />
<binding name="WebservicePrimusSoapBinding" />
</basicHttpBinding>
<customBinding>
<binding name="QuoteSoap12">
<textMessageEncoding messageVersion="Soap12" />
<httpTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint
address="https://webservices.rrts.com/rating/ratequote.asmx"
binding="basicHttpBinding"
bindingConfiguration="RateQuoteSoap"
contract="RoadRunnerService.RateQuoteSoap"
name="RateQuoteSoap" />
<endpoint
address="http://services.echo.com/Quote.asmx"
binding="basicHttpBinding"
bindingConfiguration="QuoteSoap"
contract="EchoService.QuoteSoap"
name="QuoteSoap" />
<endpoint
address="http://services.echo.com/Quote.asmx"
binding="customBinding"
bindingConfiguration="QuoteSoap12"
contract="EchoService.QuoteSoap"
name="QuoteSoap12" />
<endpoint
address="http://api.shipprimus.com/"
binding="basicHttpBinding"
bindingConfiguration="WebservicePrimusSoapBinding"
contract="PrimusService.WebservicePrimusServicePort"
name="WebservicePrimusServicePort" />
</client>
</system.serviceModel>
</configuration>
The PrimusService is the one that is not working correctly, and the full error when I try to initialize the client like WebservicePrimusServicePortClient serviceClient = new WebservicePrimusServicePortClient("WebservicePrimusServicePort"); is
System.InvalidOperationException: Could not find endpoint element with name 'WebservicePrimusServicePort' and contract 'PrimusService.WebservicePrimusServicePort'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 name could be found in the client element.
I have also tried to simply initialize a BasicHttpBinding object using the binding name and the endpoint name with no luck (short variable names for readability)
BasicHttpBinding a = new BasicHttpBinding("QuoteSoap"); // Works fine
BasicHttpBinding b = new BasicHttpBinding("WebservicePrimusSoapBinding"); // Fails
BasicHttpBinding c = new BasicHttpBinding("WebservicePrimusServicePort"); // Fails
It throws no error for binding a, but binding b and c fail with the error:
System.Collections.Generic.KeyNotFoundException: No elements matching the key 'WebservicePrimusSoapBinding' were found in the configuration element collection.
While not a direct solution, I ended up just taking the information from the app.config and creating my own BasicHttpBinding and EndpointAddress objects in code. This is more of a workaround than a fix for the problem, and I still don't know why I couldn't access the information in the app.config directly.
I followed the solution in this answer about how to consume a service without using the app.config file.
I created my BasicHttpBinding like
BasicHttpBinding binding = new BasicHttpBinding();
binding.Name = "PrimusServiceBinding"; // Completely Unnecessary
and my endpoint like
EndpointAddress endpoint = new EndpointAddress("http://api.shipprimus.com/");
and could connect to the service and retrieve information without a problem, even providing as little information as I did (basically just the address).

WCF exception--Faulted state

I added the WCF service reference to my project. Next step is to create a channel from the code.
WSHttpBinding bindingDialingType = new WSHttpBinding();
EndpointAddress endingPointDialingType = new EndpointAddress("http://wsvc.corporate.my.com/International/DialingService.svc");
ChannelFactory<IDialingService> iDialingServiceChannelFactory = new ChannelFactory<IDialingService>(bindingDialingType, endingPointDialingType);
IDialingService instanceIDialingService = iDialingServiceChannelFactory.CreateChannel();
Because I met an exception, so I guess that something wrong with my channel factory code.
The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.
To capture the exception, I had the code.
My app.config is:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_iLuCRE" />
</basicHttpBinding>
<wsHttpBinding>
<binding name="WSHttpBinding_IDialingService">
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://wsvc.corporate.my.com/LuCRE/LuCRE.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_iLuCRE"
contract="LuCRE.iLuCRE" name="BasicHttpBinding_iLuCRE" />
<endpoint address="http://wsvc.corporate.my.com/International/DialingService.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IDialingService"
contract="DialingService.IDialingService" name="WSHttpBinding_IDialingService" />
</client>
</system.serviceModel>
I used WCFTestClient to test it, however the service does work. I added the service reference to my project and I don't know the code details.
Updated:
If I used the code
DialingServiceClient client = new DialingServiceClient();
Then call the method through client, then everything is fine. Why?
Your binding element security is None. You need to also mention it when defining programmatically.
WSHttpBinding bindingDialingType = new WSHttpBinding
{ Security = new WSHttpSecurity { Mode = SecurityMode.None } };

The content type text/plain of the response message does not match the content type of the binding (text/xml; charset=utf-8)

When I connect to a web service written in Apche Axis, I get the following error:
The content type text/plain of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0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\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0'.
The app.cofig endpoint configuration is :
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="XXXSoapBinding" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://www.XXX.net/services/XXXConnect"
binding="basicHttpBinding" bindingConfiguration="XXXSoapBinding"
contract="XXX.XXXConnect" name="XXXConnect" />
</client>
</system.serviceModel>
you have a mismatch beetween basicHttpBinding and wsHttpBinding
Try with
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="XXXSoapBinding" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://www.XXX.net/services/XXXConnect"
binding="basicHttpBinding" bindingConfiguration="XXXSoapBinding"
contract="XXX.XXXConnect" name="XXXConnect" />
</client>
</system.serviceModel>

Categories

Resources