Post Image to WCF Service From Fiddler - c#

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...

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!

Remove Action (mustUnderstand) from client request

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.

System.Runtime.Remoting.RemotingException: Requested Service not found

I have the following code in my Web.Config in a remoting project which is having a reference to a dll of another class library. The class library has the following class inside it:
public class Generator: MarshalByRefObject, IGenerator
{
}
When I run the remoting project for the configured uri which is exposing the above class, I get the mentioned error in the question header.
The url I run is this:
http://localhost/documentgenerationserver/Generator.rem
<application>
<service>
<wellknown mode="SingleCall" objectUri="Generator.rem" type="ABC.Generator, Generator" />
</service>
<channels>
<channel ref="http" />
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
</channels>
</application>
Can someone advise me, how to resolve this issue?
EDIT 1: After going through an article on remoting on google, I tried appending ?wsdl to my URL above and it worked. It shows me WSDL file for my remote object. In my Client Project which is an asp.net web application hosted in IIS 7.5, when I instantiate the remote object using following:
Activator.GetObject()
It successfully instantiates, but when I use this proxy of remote to call its method, it does not reach up to that method and returns immediately.
Can some one please help me knowing, how can I at least debug it and see, what's happening. Why it is not reaching to the remote object method?
The message "System.Runtime.Remoting.RemotingException: Requested Service not found" is the expected behavior on the browser for a remoting service.

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.

Silverlight Socket Policy Not Working

I am trying to implement a data push from a Windows Service to a Silverlight app. I have created a policy server which sends this policy file:
<?xml version="1.0" encoding ="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from>
<domain uri="*" />
</allow-from>
<grant-to>
<socket-resource port="8400" protocol="tcp" />
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
Using a TCP test tool I have verified that when I connect to port 943 and send the request, I receive back that policy file.
Also, using breakpoints in my policy server I have confirmed that the Silverlight app is reaching the service and seemingly the service sends the policy file without error.
I have also confirmed that my data push service is listening correctly on the above port.
However, somehow Silverlight's connection to my data push service is always failing with a WinSock 10013 Access Denied error.
The only thing I can think is that my policy file isn't correct, although as far as I can see it meets the spec. Let me know if you'd like me to post any of my other code. Any help would be appreciated.
It turns out my port was out of range. Silverlight can only connect to ports 4502-4534.

Categories