Adding a soap message to a Service Reference in c# - c#

I have added a Service Reference that points to WSDL of the service. I can consume the service by creating a proxy and theres no issue with that. My problem is that I need to send a specific soap message , and theres some parameters that need to be include into the header and the body of the soap message (credentials and IDs).
How I can manually edit or add this soap message? without touching the app.config file?, there's a way to add the same parameters inside the code? such as:
soap:Header
soap:Body

Related

MassTransit + azure service bus consuming custom type messages

I try to consume custome type message by my MassTransit service that subscribes to a azure service bus topic.
The messages has custom type and data of message stored is in custom properties. Here is an image of message from azure service bus explorer:
When trying to consume this I got :
MassTransit does not recognizes custom type unless it is in message header :/
Is there any way to configure endpoint so it can consume this type of message ?
Without a ContentType to differentiate the message serialization from the formats supported by MassTransit, there isn't currently a way to change it. And blank or null is not a valid content type, so that cannot be used to select it.
You would need to either add a content type, or change the message format at this point. You could submit an issue and if somebody gets around to making it possible to add an empty or unsupported serializer.

How to cause a service reference to generate an empty xml tag in soap request for complex object?

I imported a WSDL into my project for a 3rd party system. (The WSDL is a nightmare)
Anyway in order for my request to receive a valid response i have been told by the 3rd party i need to send through an empty object in one of the requests.
Lets assume a valid request looks like the below:
<Request>
<UserID>123456</UserID>
<ComplexObj/>
</Request>
If i send the above XML manually in SOAP UI then I get a valid response.
However because I'm doing this in C# i have imported the WSDL into visual studio and have a service reference generated i cannot figure out a way for the request to generate the empty ComplexObj.
If i set ComplexObj to null in the code it is not included in the request.
If i create a new instance of the ComplexObj then the request includes all the variables within the ComplexObj which is also invalid.
HAve you tried to declare ComplexObjproperty to serialize even if it is null. For that you'll need to find the definition of class and add
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
for that property. That 'll include it into SOAP request as <ComplexObj xsi:nil="true" />

Implementing a SOAP web service

I have a WSDL definition for a SOAP service and I have successfully generated *.cs file from it using SvcUtil.
Implementing client is quite straightforward - I just need to call the necessary functions from the generated *.cs and that's it.
Implementing server seems more complicated. As I understand I need to implement an interface from the generated *.cs and then use some magic to turn it into the web server.
But I don't need a new web server, I already have a web server written in C# which already has many functionality unrelated to the SOAP service that I need to implement. I don't want to create another web server but I want my SOAP service to be just a part of my existing application (server), that is my server can answer e.g. requests http://example.com/request1, http://example.com/request2 etc. and I want this SOAP service to be just http://example.com/request3.
Since HTTP is already handled by my server I don't need .NET to handle it for me, basically my server can accept client connections and call the necessary handler based on the URL. I have a handler for SOAP request which looks approximately like this:
MyResponse HandleSOAPRequest(MyRequest request)
{
// 1. parse soap message from request.body
// 2. process it
// 3. generate response, serialize it in SOAP format and return it
}
The question is - can I rely on WSDL definition and .NET libraries to do it?
Currently I'm parsing SOAP request using XDocument and manually extract fields from it and serialize using simple string concatenation. Using .NET built-in functions to serialize or parse XML doesn't work. That is if I try to serialize response from an object of the class defined in the generated *.cs file then produced XML is different from what is expected by the protocol, similarly, if I try to parse request as an object of the class defined in the generated *.cs file I get error because XML parser expects different format. This applies to both the SoapFormatter and XmlSerializer.
Since .NET can implement client this means that everything that is necessary to parse and serialize SOAP messages is already implemented, I just need to figure out a way how to use this functionality.
The documentation for ServiceModel wasn't very helpful.
The easiest way would be to start the service via the ServiceHost:
ServiceHost host = new ServiceHost(typeof(YourService));
host.Open();
(I assumed here the configuration will come from the app.config and will not be setup in code like in the linked example below.)
How to: Expose a Contract to SOAP and Web Clients
The only drawback of this is that the application has to run with admin rights or otherwise a weird cofiguration is necessary.

Soap Header Action Not Understood

I have imported a WSDL via the Service Reference dialog box in VS2010 (asmx not WCF) which contains a SendMessage method which I need to call, passing it Xml and a Command name. I'm also passing the URL of the WS. When I call this method, it causes the following exception:
SoapHeaderException: Soap Header Action Not Understood
I think I am able to read the Soap request via Fiddler, and it contains no Soap Header information. I would have expected C# to add this automatically since all the required information to create it is present.
How do I ensure the Soap Header is added??

C#asynchronous invocation with wsa replyTo

I am trying to make an asynchronous call to a web service using BeginXXX and EndXXX methods from C# client. I am using a proxy class generated by using SvcUtil.exe.
The soap message that I expect to send should contain soap header elements for ws-addressing which include tags:
'wsa:Action'
'wsa:MessageID'
'wsa:ReplyTo'
'wsa:To'
However the soap header section is currently empty and only soap body contains body information.
Without the wsa tags, it looks like a synchronous call.
Is there a way to use proxy generated in C#, to invoke a service asynchronously such that the soap message contains wsa tags?
Appreciate any input with regards to this

Categories

Resources