I have the following contract method call in a soap wcf service contract:
[SoapHeader("UserId", typeof(Header), Direction = SoapHeaderDirection.In)]
[OperationContract]
string DeleteVideoRequest(Guid id);
I'm using the wcfextras library to read in a userid header value (or I want to anyways). The problem I'm running into is once I add the soapheader attribute the generated service signature wants a DeleteVideoRequestRequest (made up of the user id and guid id) object instead of a Guid. I'm not sure what is causing this to occur. Is this the expected behavior? I would expect that the signature stay the same, and then you would use the wcfextras code to read the header. Could I be missing something or doing something wrong?
I figured this out. I was missing config values for the extras on the client side.
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 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.
I am following along in the .6 release of the WCF Web API chm file. I have built my service and everything works fine when I access it via IE. But when I create my console app, I don't understand how the client can know about the "contact" type. Sure I can add a reference, but how would some other client out there in the world know about the types?
List<Contact> contacts = resp.Content.ReadAs<List<Contact>>();
How would a client know about changes to the Contact class?Thanks.
Using the SOAP based WCF bindings, the client would normally generate a client off the WSDL, which would specify these custom types.
However as far as I know, in the REST based world of Web API, there is no facility for doing that. It is expected that the 3rd party customer / programmer making the client is given the data contract in some other form, and makes a compatible class.
In other words, there is not really an automatic way of doing that.
Every property on your client type that matches a property (Name/Type) in the response type is mapped by ReadAs<T>.
If you have a string property "Name" on your response type and your client type, its value is being parsed.
You don't need a reference.
Update: If you don't want to work with a contacts type on the client side you could try something like this:
var json = JsonValue.Parse(response.Content.ReadAsStringAsync().Result);
If your contact type on the server side had a property "Name" you should be able to do the following:
var name = json["Name"];
(Assuming your response was a single contact - in case of List<Contact> "json" would be of type JsonArray - you should get a clue... here is a sample showing usage of JsonValue and JsonArray).
Concerning "changes on contact type" please read this.
Microsofts's WCF is easy to work with when you create Web services where each message has it's own Web method. WCF generates all of the WSDL and everything is easy.
What I want to do is have one Web method that accepts multiple different messages (I don't want to add a mew method every time I add a new message type). The messages themselves will have header information that identify the message type. Once I know the message type, I'll know the structure of the rest of the message.
The only way I've found to do this with WCF is to have the method accept a string, which I parse in as XML and and use. However, I can see no clear way to publish the various message types in the WSDL; so, the whole service is essentially undocumented.
Anyone know of a technique to use in WCF?
You can write an operation contract that accepts any message by setting the Action to * and having it take in a Message object:
[ServiceContract]
public interface IMessageContract
{
[OperationContract(Action = "*", ReplyAction = "*")]
Message ProcessRequest(Message request);
}
The Message object gives you access to the headers and has methods to deserialize the body.
To export your own WSDL, you will need to implement IWsdlExportExtension on a contract behavior or operation behavior and attach it to your service. This will give you access to a WsdlExporter, and you can create a ContractDescription yourself and call ExportContract to have it appear in the generated WSDL.
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.