views:

1057

answers:

1

Hi,

I've want to add specific custom headers on my wsdl for incoming soap message so i've added the required tags into the header node of the web.config like below:

 <headers>
   <Tag>Value</Tag>
 </headers>

However, this works fine if the 'Value' in the custom tag is set to 'Value' when I change this value the service kicks it out giving the below error;

'DestinationUnreachable - The message with To 'http://localhost:3537/Service1.svc' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher. Check that the sender and receiver's EndpointAddresses agree.'

So how can I specify variable values for the actual value in between the tags?? like in url templates i.e.

 <headers>
   <Tag>{variable value here}</Tag>
 </headers>

Any ideas, or am I going about custom headers the wrong way? I don't want to use a messageContract as we use RPC style soap over document style.

Also another curious thing is that for the message to be valid the custom defined in the header element must specify a 'IsReferenceParameter="true"' attribute with a ws-addressing namespace otherwise it throws the above error?

 <Tag a:IsReferenceParameter="true">Value</Tag>

Can anyone explain this to me?

Thanks in advance

Jon

+1  A: 

I can't really explain the concrete question you have - but typically, you would add custom headers to WCF calls in code, often using a behavior, rather than from web.config. Not sure if that even works, really.

What your custom headers behavior could do, of course, is read its values that it'll send from a config file or a database table or something else.

But if you really want to enforce the SOAP headers in your messages, I think your best bet would really be to use message contracts. Why is it you can't or don't want to use message contracts?? That's really the sole purpose of message contracts: defining the explicit SOAP message layout, including custom headers.

See some articles and blog posts on the topic:

This blog post here show how to inject custom SOAP headers into the WSDL being generated by implementing a custom "WsdlExporter" class - maybe that's the way to go for you?

Plenty more resources available if you just google for it - this is a very common scenario, and lots of folks have already implemented it in a great number of ways, with some ingenious solutions, and blogged about it - you should have no trouble finding all the answers out there!

Marc

marc_s
I want to require a custom header on the service side and using the header tag displays the tag in the WSDL document. Do you have any idea why I can't have variable values in the custom defined tags in the web.config? Jon
Jon
Ah okay, sorry, I didn't catch that "require the header in WSDL" part. I don't know how you could specify a variable name as placeholder, sorry. And I'm afraid the only solution I see for describing SOAP headers in your contract is indeed using a MessageContract. That's exactly what it's there for.
marc_s
hi, sorry i don't think i have explained it very well, in the custom tag nodes i don't want to specify a variable, i want the content to be anything i want it to be not just 'VALUE'. for example: <Tag>somevalue</Tag> <Tag>anotherValue</Tag>When i try and pass any data other than 'Value' i get the error defined in my first post.
Jon
Where exactly in your web.config do you specify those headers?
marc_s
In the service tag - <service behaviorConfiguration="WCFTestService.Service1Behavior" name="WCFTestService.Service1"> <endpoint address="" binding="customBinding" bindingConfiguration="SOAP11_With_WS_Addressing" name="" contract="WCFTestService.IService1"> <headers> <Tag>Value</Tag> </headers>
Jon
Those are not SOAP Headers. Those are WS-Addressing headers.
John Saunders