I have a WSDL I need to write a WCF client against (in C#). In the WSDL one of the elements is:
<xs:element name="TransactionDateTime" type="xs:date" />
For the moment I'm using a mock service created through SoapUI with that wsdl, so I can get mock responses where I'm trying to populate that TransactionDateTime using a groovy script.
My problem is whatever I use it seems to raise an exception in the client when trying to deserialize the reply body
String was not recognized as a valid DateTime
These are examples of what I've tried to return in the groovy script
new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(new Date())
javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar(GregorianCalendar.getInstance())
If I try to hardcode it in the xml that I use as a response as
2014-09-11T10:11:555
which is by the way the format specified in the docs that came along with the WSDL it raises the same exception
Further more if I just hard code in the response a date like this '2014-09-12' instead of raising an exception it populates it as 01/01/0001 00:00:00 in the DateTime property of the C# class the response is populating
Can anyone give me any hint on which path should I follow?
UPDATE:
Wasn't 100% sure but I reckon the reason is the same as for this question or explained in other webs, WCF doesn't support xs:date. So I would ask the third party to change the WSDL and send the date as a string that I will parse. Can't thinkg of a better option
Related
I have a WCF Service; this service has an operation that receives an argument of type Request. This is only the base type, and when calling the operation we actually send a value of type Request_V1 (which inherts from Request), that has the complete implementation of the request I want to send.
When trying to test the service using soapUI, I'm able to create the complex type of type Request_V1 (adding the proper namespace) but for some reason, the service is receiving the value as if it were of Request type.
Reading about ServiceKnowType, I found out here that I need to specify somehow explicitly in the client this inheritance relationship, but I haven't found any info regarding how to do it on soapUI
Has anybody experienced and solved the same issue?
Thanks
You also have to specify the type in the SOAP message.
For example
<Request i:type="d:RequestV1">
...
where i is defined as XML-Instance namespace
On service side, you need to typecast to specific derived type.
operation (Request request){
if(!(request is Request_V1)){
throw Excetion("Unknown type!");
}
var request_v1 = Request as Request_V1;
// use request_v1
}
On SOAP UI side, specify type as below:
<soapenv:Body xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<ns1:OperationName>
<ns1:request i:type="ns2:Request_V1">
Make sure you have defined ns1 and ns2 before referring to them.
You don't specify the inheritance in the client, rather in the service. SOAPUI shouldn't have a problem with that. Check you have the correct declarations on your data contracts. This might help - Deserialize Abstract Class.
I am using WCF Web API Preview 6 with its inbuilt Test Client to request a resource by Id. The object returns with all its data except for the ‘CreateDate’ and ‘LastModifiedDate’ properties which are of type DateTimeOffset and are empty. I have tried setting the values manually by calling DateTimeOffset.UtcNow and DateTimeOffset.Now and although the values are set on the object they never make it through to the other end in the response.
I have also tested this by changing my property types to DateTime and manually setting their values by using DateTime.Now and everything works fine and I get what looks like a DateTimeOffset value.
<CreateDate>2011-12-13T16:15:47.4269538+00:00</CreateDate>
<LastModifiedDate>2011-12-13T16:15:47.4269538+00:00</LastModifiedDate>
Does anybody know if there is a problem with the use of the DateTimeOffset type in Preview 6 or is it something I am doing wrong? I have had a similar problem with filtering the fields using oData (see SO question)
I have also submitted this bug report to the WCF Web API codeplex site on the filtering issue. However that was over two weeks ago and haven’t had any response.
After many hours of testing and debugging I am running out of options on this one! So if anybody out there can provide me with some helpful hints it would be much appreciated.
It's not a Web API issue, it's Microsoft serialization issue. The XmlSerializer does not handle DateTimeOffset. I believe it has the same issue with TimeSpan.
Just implement IXMLSerializable on your object and handle it yourself.
See here How can I XML Serialize a DateTimeOffset Property?
Web service newbie... Please bear with me.
I was given a WSDL file to import into my vb .NET project. I understand that this is a contract which is supposed to tell me how to use the related web service. That's where my problem comes in. I see all kinds of classes, properties, Interfaces, etc. in the imported service reference. Nothing telling me that "if you have X, Y, and Z as inputs call this function to return W".
At the risk of sounding too vague, what is it that I should be looking for that tells me how I should be using this? How do I know which functions to call and from what classes to call them from? Should I expect some documentation to be provided with the WSDL or is the WSDL supposed to be enough for me to look at it and say "ahh, that's how this is used!".
I've read through the various WSDL tutorials out on the web and they gave me a basic understanding (I think...?). I'm missing something somewhere though and I'm really sure where.
Thank you for any assistance.
The classes that have been generated are easy to use.
Basically you would have one client class, and in that class one method for each endpoint/operation declared in the WSDL.
In addition, there should be one class for each complex type defined in the XSD part (the operation input arg object and output result object).
You can then invoke your WS in a way similar to the following (simplified) example.
Try
Dim service As New MyServiceRef.MyServiceClient()
service.Open()
Dim output As MyServiceRef.myCallResponse
Dim args As New MyServiceRef.myCallRequest
args.arg1 = 1
args.arg2 = "A"
output = service.myCallRequest(args)
...
Catch ex As Exception
treat ( ex )
End Try
The WSDL will tell you or, perferably, a SOAP library how to communitcate with the SOAP server. A SOAP service can be an interface to get data for almost anything.
However, if the function names and parameters are not named well, it could be very vague what data you are to send to the SOAP service and what the response will be.
Most of the time, it should be documented. You should get those documents or learn what the service actually does from the service provider. The WSDL is not really meant to be for human consumption. Though, if you are writing your own XML, then yes, you'd need to pay attention to the WSDL. If a library is creating the XML for you, it usually works with the WSDL to find out how to structure the XML and read the response.
When you add reference of the web service, it creates a proxy for you to call the web methods on the server. Here is a simple tutorial for consuming web services in VB.NET
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.
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.