Remove Action (mustUnderstand) from client request - c#

I have a remote endpoint not under my control for which I have no WSDL but I have samples of SOAP messages. Since I really do not want to be playing with scissors and making soap envelopes by hand, my idea was to create service/data contracts that will (once used in WCF client) generate desired SOAP requests and parse responses. I immediately encountered a problem with the first method in the fact that each envelope seems to contain Action addressing in header:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">urn:IService1/Auth</Action>
</s:Header>
<s:Body>
<Auth>
<login xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Password i:nil="true" />
<userName i:nil="true" />
</login>
</Auth>
</s:Body>
</s:Envelope>
This messes up the callee which profusely objects to my message. I tried different configuration approaches (I use web.config to configure the mock service and client), but nothing seems to remove this annoying Action node. Any way to solve this without doing what I dont want to be doing (playing with XML by hand)

My problem is solved my moving XML serialized format, as described in Force parameter as Service contract attribute. When I switched to XML formater, the Action header stopped being generated. If someone, however, knows how to remove it in DataContract classes, feel free to show, I'm sure it will be useful.

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!

SOAP version in Envelope from code generated by WSDL

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" />

Post Image to WCF Service From Fiddler

I have been working on WCF Services. I have a service that accepts a few parameters including Image. Here is my Request XML:
<?xml version="1.0" encoding="UTF-8"?>
<GPProcess xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Action>
<Device />
<GenopalAuthorization />
<P1x>0</P1x>
<P1y>0</P1y>
<P2x>0</P2x>
<P2y>0</P2y>
<PalletName />
<Picture i:nil="true" />
<PictureShare>false</PictureShare>
<PictureURL />
</Action>
</GPProcess>
The problem is that, I want to test this Web Service on Fiddler. I need help that how can I post an Image to Web Service through Fiddler? and what should be the content-type?
With Best wishes
It might be better to create a proxy class to call your service and build a simple client that uses that proxy. You can then monitor the traffic between the client and the service using Fiddler...

silverlight: clientaccesspolicy.xml any localhost?

I have an (otherwise) functional clientaccesspolicy.xml file that is not working correctly for requests from localhost unless a specific port is given. Below is my file installed on my development server that functions properly for any requests except those coming from any localhost. It works correctly for locahost requests on port 11712, but won't accept any others. This is what I would expect... no problem so far...
<?xml version="1.0" encoding="utf-8" ?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="SOAPAction">
<domain uri="http://*.myDomain.us"/>
<domain uri="http://localhost:11712/"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
I want to completely open up access to any localhost regardless of port. so if I change the domain node thusly:
<domain uri="http://localhost:*" />
or
<domain uri="http://localhost*" />
or
<domain uri="http://localhost"/>
do not work, failing as a cross-site error. The only way localhost access works is if I specify the exact port, which means that I'd have to specify any potential client app in the list (or require them to use a specific port).
alfonso pointed me in the correct direction. According to Microsoft, the clientAccessPolicy.xml file does NOT allow wildcards in the port:
Silverlight does not support wildcards for the port field in
clientaccesspolicy.xml, and neither does it support the to-ports
attribute in the crossdomain.xml. Can you give us a little more
information so we can think about adding support for this in the
future please - why do you need to be able to launch your XAP from
multiple different ports?
from: http://forums.silverlight.net/p/48275/128264.aspx

Does a .net 2.0 web service always use Soap over http?

Im doing research and I downloaded a test app that calls a standard .asmx service. The service is being called using a standard POST request. Im slightly confused because I thought .asmx services always used SOAP? Or is the ability to communicate with HTTP (POST) something that was introduced recently?
.NET Web-Services uses the one protocol you choose. By deafult it is the SOAP, and POST requests are allowed.
Standart help page automatically created by .NET:
POST /demo/MSDN/PerfCounter.asmx HTTP/1.1
Connection: Keep-Alive
Content-Length: 150
Content-Type: text/xml
Host: localhost
User-Agent: MS Web Services Client Protocol 1.0.2204.19
SOAPAction: "http://tempuri.org/PerfCounters"
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<soap:Body>
<PerfCounters xmlns="http://tempuri.org/"/>
</soap:Body>
</soap:Envelope>
Also you can enable the GET method:
<configuration>
<system.web>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>
</configuration>
This works from .NET 1.1
No, ASMX webservices are not limited to SOAP. You can use the ScriptMethodAttribute to specify the a HTTP verb for a webmethod. This was introduced in .Net 3.5. For example:
[ScriptMethod(UseHttpGet = true)]
public string MyMethod()
{
return "Hello World";
}
SOAP is a standard that you may choose to use. It's based on XML. If it's something simple, than I'd use JSON. Web services are not limited to POST. You should be using POST when you run Create/Update/Delete routines and you should use GET when you run data retrieval routines.

Categories