Why am I getting an InvalidOperationException after adding a [MessageContract] attribute?

StackOverflow https://stackoverflow.com/questions/14380176

  •  16-01-2022
  •  | 
  •  

문제

The operation 'PRPA_IN201301UV02' could not be loaded because it has a parameter or return type of type System.ServiceModel.Channels.Message or a type that has MessageContractAttribute and other parameters of different types. When using System.ServiceModel.Channels.Message or types with MessageContractAttribute, the method must not use any other types of parameters.

I'm running a WCF on a console host, this is the contract:

[MessageContract]
public class opRequest
{
    [MessageBodyMember]
    public string myProperty;
}

[ServiceContract(Namespace = "urn:hl7-org:v3")]
public interface IHL7v3
{
    [OperationContract(Name = "PRPA_IN201301UV02", Action = "urn:hl7-org:v3:PRPA_IN201301UV02")]
    string PIXManager_PRPA_IN201301UV02(opRequest clientID);
}

It does run when I remove from opRequest class the [MessageContract] and [MessageBodyMember]

I'm completely not sure if that will get me to what I need, so i'll give the wider scope - I'm trying to get the SOAP body to be without an enclosing tag of the parameter name. for example (the body extract from the SOAP message) instead of:

<s:Body>
<PRPA_IN201301UV02 xmlns="urn:hl7-org:v3">
  <clientID>the xml document is enclosed</clientID>
</PRPA_IN201301UV02>

I want it to be like this:

<s:Body>
<PRPA_IN201301UV02 xmlns="urn:hl7-org:v3">
  my given xml document will go here...
</PRPA_IN201301UV02>

I need it like that to conform to a standard (HL7v3 PIX Manager SOAP Web Service).

Any ideas?

도움이 되었습니까?

해결책

Looks like you should use MessageContract for your return parameter as well

EDITED: Have a look at this MSDN article for more details Using Message Contracts If you design your contract with messages you can't use other types either as a parameter or a return value.

Here is a code snippet from the article:

[OperationContract]
bool Validate(BankingTransaction bt);
// Invalid, the return type is not a message contract.
[OperationContract]
void Reconcile(BankingTransaction bt1, BankingTransaction bt2);
// Invalid, there is more than one parameter.

다른 팁

Did you try to use an XMLDocument as the input parameter instead of opRequest? You will also have to mark the interface to use the XML Serializer:

[ServiceContract(Namespace = "urn:hl7-org:v3")]
[XmlSerializerFormat]
public interface IHL7v3
{
    [OperationContract(Name = "PRPA_IN201301UV02", Action = "urn:hl7-org:v3:PRPA_IN201301UV02")]
    XMLDocument PIXManager_PRPA_IN201301UV02(XMLDocument doc);
}

I am presuming you are also returning XML.

Please note that this is wide open - any XML can be sent which may not be what you intend as there no explicit data contract.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top