SOAP version in Envelope from code generated by WSDL - c#

I'm working on a solution with a service generated by WSDL. When I call the service I get a Bad Request-Error. I've enabled tracing and the message sent has the following envelope:
<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">
When I try to use cURL I get an error saying "InputStream does not represent a valid SOAP 1.1 Message" and of course works perfectly fine when I change xmlns:s to use SOAP version 1.1.
In the WSDL the binding is:
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
which as, from what I've found, SOAP 1.1.
How can I modify the WSDL or the generated code to send the message with correct SOAP version?

All there was to it was to add textMessageEncoding in the binding
<customBinding>
<binding name="wsHttpEndpointBinding">
<textMessageEncoding messageVersion="Soap11" />

Related

WCF Client Message Format c#

I'm creating an application that consumes a WCF web service. When I test a certain operation in SOAP UI, it works, however, when I test in VS2017 console app, I receive an error:
"The content type text/html;charset=UTF-8 of the response message does not match the content type of the binding"
I used Fiddler to grab the request from my console app, and I've narrowed the issue down to some of the formatting in the SOAP request. When I format my console app request to match the request Fiddler generates, it works. There are prefixes that are defaulted in my request that seem to be causing the issue, as well as xmlns declarations. I need to know how I can modify these parts of the request to conform to the web service which I have absolutely no control over (major corporation).
The prefixes s and h need to change to different values. I took this request and put it into SOAP UI, swapped the s and h throughout to match how Fiddler is passing in the request, and it works. I also had to move xmlns:h up to the Envelope level. Is there something I can change in my config file? Is there something with Message Contracting that I can easily implement? I need to be able to format this correctly, but I'm not sure what the best way would be.
BAD:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:FooListHeader xmlns:h="http://foo.foo.com/Hello" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<h:FooList>
<h:FooStatement>
<h:Title>Foo</h:Title>
<h:Value>123</h:Value>
</h:FooStatement>
</h:FooList>
</h:FooListHeader>
</s:Header>
<s:Body>
<GetFooRequestType xmlns="http://foo.foo.com/Hello">
<MessageRequest xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<ConFooRequest/>
</MessageRequest>
</GetFooRequestType>
</s:Body>
</s:Envelope>
GOOD (how can I convert above bad example to this good example below in my app?):
<soapenv:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:foo="http://foo.foo.com/Hello">
<soapenv:Header>
<foo:FooListHeader xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<foo:FooList>
<foo:FooStatement>
<foo:Title>Foo</foo:Title>
<foo:Value>123</foo:Value>
</foo:FooStatement>
</foo:FooList>
</foo:FooListHeader>
</soapenv:Header>
<soapenv:Body>
<foo:GetFooRequestType xmlns="http://foo.foo.com/Hello">
<foo:MessageRequest xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<foo:ConFooRequest/>
</foo:MessageRequest>
</foo:GetFooRequestType>
</soapenv:Body>
</soapenv:Envelope>
Service Reference Image
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="foo" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://Foo.foo.com/foo/foows.svc"
binding="basicHttpBinding" bindingConfiguration="foo"
contract="Service1Reference.IFooServices" name="foo" />
</client>
</system.serviceModel>
</configuration>
Everything I can find on the internet about this topic mostly revolves around the service side of things, not the client side.
The company has provided me with a .wsdl file and an XML reference file. I'm not quite sure what to do with the reference file, but I have loaded the .wsdl file directly under "Add Service Reference" in my application. I could not discover the service using the endpoint like I have in previous projects that I have worked on, so I had to store the file locally on my PC and specify the path to it directly when I added the service reference. Again, I am not able to discover the service using the typical ?wsdl address most likely due to service config settings for security purposes. Thanks so much for any responses!

WCF Security Header Removal

I have read countless forum posts and articles on this issue and am still unable to find a solution.
I am running a WCF service with the following binding:
<customBinding>
<binding name="BasicBinding">
<security authenticationMode="UserNameOverTransport" />
<textMessageEncoding messageVersion="Soap11" />
<httpsTransport />
</binding>
</customBinding>
Everything is working fine and I am locally able to make requests using the appropriate credentials and the response is served as expected. I have just received information from the consuming client that the Soap security header is causing issues for them:
<s:Header>
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<u:Timestamp u:Id="_0">
<u:Created>2017-12-20T19:17:29.322Z</u:Created>
<u:Expires>2017-12-20T19:22:29.322Z</u:Expires>
</u:Timestamp>
</o:Security>
They inform me that the 'mustunderstand' part is incompatible with their system. I have read that changing to a custom binding will fix it, however as you can see above this has been done and is still showing the security header.
I have read about interceptors and manipulating the response object but I've been unable to see how it all fits together. Has anyone actually solved this problem completely? I am basically looking to remove all header information from the response.

Kerberos Over HTTPS

I have a WCF service hosted by a Windows Application of my own. I want the service to authenticate the client at the transport level using the client's Certificate and when the client communicates with the service, it must pass its Kerberos Ticket of the client's user account. Looking around on the internet i found this configuration for the service:
<bindings>
<customBinding>
<binding name="Kerberos (MsgHeader) over Transport (Certificate)">
<textMessageEncoding messageVersion="Soap11" />
<security authenticationMode="KerberosOverTransport">
<secureConversationBootstrap />
</security>
<httpsTransport requireClientCertificate="true" />
</binding>
</customBinding>
</bindings>
They say that this configuration worked with Microsoft's help. Now, i tried to duplicate this configuration through code, so i used the following snippet:
BindingElementCollection elementCollection = new BindingElementCollection();
elementCollection.Add(SecurityBindingElement.CreateKerberosOverTransportBindingElement());
elementCollection.Add(new TextMessageEncodingBindingElement() { MessageVersion = MessageVersion.Soap11 });
elementCollection.Add(new HttpsTransportBindingElement() { RequireClientCertificate = true });
return new CustomBinding(elementCollection);
I configured the endpoint with this binding along with a valid certificate bound to the port. I then added a service reference at the client project in Visual Studio.
To this end, everthing is working great! I also configured the client to send its certificate when communicating with the service, this also worked fine. However, when I try to invoke any method of the service, I get the following error:
An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail.
And when I examined the inner exception, I found the following error:
An error occurred when processing the security tokens in the message.
Any help, please? Do i need to configure the client further to send its Kerberos token, or what?
P.S. The service and client machine clocks are synchronized. In addition, the service and the client are on two different machines joined to a domain.

C# client consuming java-websphere SOAP service

I am trying to consume a java-based service from .Net 4.0. (C# Console/Windows Service)
I have added the service reference using VS's Add Service Reference Dialog.
The service is hosted on WebSphere 8 and WSDL definition is generated using cxf.
Client app is running on Windows Server 2008 R2 SP1. But I don't think any windows update is applied after SP1.
Problem is from time to time All the calls to service methods return an exception. The error is as follows:
The content type text/xml;charset=UTF8 of the response message does not match the content type of the binding (application/soap+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: '<?xml version="1.0" encoding="UTF-8"?><wsdl:definitions name="MyServiceImplService" targetNamespace="http://impl.webService.myService.com/" xmlns:ns1="http://webService.myService.com/" xmlns:ns2="http://cxf.apache.org/bindings/xformat" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="http://impl.webService.myService.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:import location="http://10.1.1.1/myService/webService/myService?wsdl=myService.wsdl" namespace="http://webService.myService.com/"></wsdl:import>
<wsdl:binding name="MyServiceImplServiceSoapBinding" type="ns1:myService">
<soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"></soap12:binding>
<wsdl:operation name="disableCard">
<soap12:operation soapAction="" style="documen'..
Here's my client app's WCF config:
<system.serviceModel>
<bindings>
<customBinding>
<binding name="MyServiceImplServiceSoapBinding">
<textMessageEncoding messageVersion="Soap12" />
<httpTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://10.1.1.1/myService/webService/myService?wsdl"
binding="customBinding" bindingConfiguration="MyServiceImplServiceSoapBinding"
contract="MyServiceReference.myService" name="MyServiceImplPort" />
</client>
</system.serviceModel>
I don't think this has anything to do with WCF configuration since all the methods work fine and all of a sudden, All of them return this exception.
The error seems to show up randomly with no apparent reason. Sometimes after 2 days and ~1,000,000 requests and sometimes after half an hour. But when this exception shows up, every call to the service returns this exception.
On the service side, there's no log that the call even reaches the java application. Seems like WebSphere sends the wsdl definition instead of passing my call to service.
Closing and relaunching the client app does not make the error go away. Only a complete system restart makes the error to disappear. (Update: it seems like removing ?wsdl from the endpoint address, removed the need to restart the system and restarting the client app is enough to make it work again.)
When facing the error, I have called the service methods with Soap UI and got the results with no exception. So there's probably nothing wrong on the service side.
My only guess is that this is a bug in .Net Framework 4.0.
Any help is greatly appreciated.

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

I created WCF service and testing WCF client using stand alone application. I was able to view this service using Internet Explorer also able to view in Visual studio service references. Here is the error message.
"The content type text/html; charset=UTF-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8)."
Could you please advice what could be wrong?
Thank you.
Since the returned content type is text/html, I suspect your call result in a server-side error outside of WCF (you are receiving an HTML error page).
Try viewing the response with a web debugging proxy such as Fiddler.
(Edit based on comments) :
Based on your comments, I see that your WCF is hosted under Sharepoint 2010, in a form-authenticated site.
The error you are receiving is due to the fact that your your WCF client is NOT authenticated with sharepoint -- it does not have a valid authentication cookie. Sharepoint then return an HTTP Redirect to an html page (the login.aspx page); which is not expected by your WCF client.
To go further you will have to obtain an authentication cookie from Sharepoint (see Authentication Web Service) and pass it to your WCF client.
(Updated edit) :
Mistake: The site is using claim based authentication.
Although this is not necessarily due to cookies or form authentication, the explaination of the provided error message remain the same. An authentication problem cause a redirection to an HTML page, which is not handled by the WCF client.
This may be helpful, check the url rewrite rules in ISS 7. This issue will occur if is you didn't configure rule properly.
It sounds like your application is expecting XML but is receiving plain text. What type of object are you passing in?
text/html is SOAP 1.1 header and Content-Type: application/soap+xml is SOAP 1.2
Verify your bindings and return header.
It should be same either 1.1 or 1.2
Add the following code to the web.config server project
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBinding_IService">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="Service">
<endpoint address="" name="BasicHttpBinding_IService"
binding="basicHttpBinding"
bindingConfiguration="basicHttpBinding_IService"
contract="IService" />
</service>
then update client web service,After the update, the following changes are made web.config
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<endpoint address="https://www.mywebsite.com/Service.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
contract="Service.IService" name="BasicHttpBinding_IService" />
I hope to be useful
i was getting this error in NavitaireProvider while calling BookingCommit service (WCF Service Reference)
so, when we get cached proxy object then it will also retrived old SigninToken which still may not be persisted
so that not able to authenticate
so as a solution i called Logon Service when i get this exception to retrieve new Token

Categories