Fix problematic server response in WCF - wcf

I am using WCF as a client for a java web service. I have not control over the server side.
In the response I get from the web service there is no xmlns attribute on the first element inside the soap headers. Because of this WCF returns null as the result of web service call.
Apart from the missing xmlns the response is perfect and if I add the xmlns using fiddler then everything works as expected. I don't know enough about SOAP to know if the xmlns attribute is really required.
Is there a way to avoid this problem, either getting WCF to ignore the missing xmlns attribute or even a hook that would allow me to manually munge the response before it gets to WCF?

This appears to be a pretty old question, so I'm not sure if you ever addressed this. If you are working with a WCF client for a Java Axis service, you will find that you will need to get used to using MessageInspectors to override the behavior of the request and response.
Using the AfterReceiveReply method you should be able to copy the original message and alter the headers. Also check out Step 5 from this MSDN article.
You can't alter the response headers directly in this method as far as I can see, because they are read-only, therefore copying and then replacing the reply with a doctored version is the only way I can think of to correct the missing namespace.

Related

How to fix WrongInputException in ASP.NET Core?

I want to use a SOAP web service prepared by another team, used internally in my new REST API prepared in ASP.NET Core. My web service client code was scaffolded with WCF Web Service Reference Provider Tool. I cleaned up code (e.g. I changed property and method names) according to my team's naming convention.
When I send requests by my new REST API, I received WrongInputException. I checked all the parameters from an example request, all of them are in the same place in my C# code consuming scaffolded client.
I don't know what message exactly is sent by my new REST API.
In my case, the main cause of the described behavior and WrongInputException was premature refactoring. I changed the names of properties in the web service client without knowledge of the consequences.
E.g. if the element in the request body is objectRefNum, then I cannot simply change the related property in the scaffolded service reference class, because - without extra configuration - that name is copied with the same letter case to the request body of the SOAP envelope. The SOAP envelope should be encoded in the case-sensitive mode.
To trace the raw request body send by my new REST API in ASP.NET Core, I followed instructions from this excellent answer.
(Note, BTW, that kind of error (applying inappropriate letter case) could be handled by IDE, at least as a warning, but it is not, so: we need to be careful when we make refactoring, even if we have unit tests covering all the paths, and even if we use semantic renaming supported by IDE.)

WCF-service with xsd generated dataclasses returns empty objects

I have an xsd-file with which I generate dataclasses (with xsd.exe or WSCF-blue) for building a WCF-service.
Then I add the generated classes to the operations in the WCF-service like this:
MyGeneratedClassOUT operation1(MyGeneratedClassIN request)
When I call that operation from a client, the client gets back MyGeneratedClassOut request filled with null-values, even tough i fill them up server-side.
Does anyone have an idea how to solve this?
Could this be a problem in the XSD-file or in the WCF configuration?
This is most probably a namespace issue. Check with Fiddler if the request and response have the same namespaces.

sudzc generates bad soap request

I used sudzc to access web services. However the jboss server side didn't like the soap message generated by sudzc. I suspect that this issue is about namespace... Have anybody exprienced this before?
I had the same problem and was able to fix it by removing the default namespace (xmlns=) altogether and search/replacing all method names, adding an explicit namespace as prefix
to all names.
The main differences I see is Sudzc not including an empty header, and uses different namespaces such as soap instead of soapenv as well as set the default namespace of the document. I have no experience with JBoss but it may not be able to handle these differences (although I would think it would) but you can first try including an empty header. SudzC is open source if you want to check out what is happening.
Check the response from web service. Then modify the source code according to the response error. Check this post as an example.
sudzC SOAP web service namespace problem

Can we identify if WCF Request is coming from our Silverlight APP or some place else?

Can we identify if WCF Request is coming from our Silverlight APP or some place else?
You could possibly declare a [MessageContract] and define a header in there, which your Silverlight app could set to a known, defined value.
Marc
The headers should already have requester info in them, and you should be bale to parse it out and tick up a counter or whatever on the server side. I would think marc_s's suggestion of MessageContract would be the simpler solution however.

View underlying SOAP message using vb.net

I have a VB.NET web service that calls a third party web service. How can I view the SOAP message generated by .NET before it is sent to the third party web service and how can I see the SOAP response before it is serialized by .NET.
When creating a standalone EXE, I see the Reference.vb file that is automatically generated, but don't see a similar file when my project is a web service. I have found lots of C# code to do this, but none in VB.NET.
Edit - Fiddler and TCP loggers are great, but will not work for my purposes. I need to be able to access the raw SOAP messages from within the application so I can log them or modify them. I need to do more than just see the messages going back and forth.
You can use fiddler or a tcp sniffer to filter and identify all outgoing and incoming traffic on your host.
This is if you want to see the xml request and response.
How about using an extension to allow you to examine the SOAP message?
Accessing Raw SOAP Messages in ASP.NET Web Services
http://msdn.microsoft.com/en-us/magazine/cc188761.aspx
I was trying to do the same thing and this seems to work for me:
Dim message As String = OperationContext.Current.RequestContext.RequestMessage.ToString()
I didn't think it would be that easy since most of the time ToString() returns the name of the class, but I tried it out and low and behold.
I know you asked this back in January so if since then you've figured out a better way let me know.
Please note that if you're catching the exception in a class that implements IErrorHandler then you have to perform this operation from within the ProvideFault() method instead of the HandleError() method because the context is closed before it gets to call the HandleError() method.
Hope this helps.