0
我有一個WCF服務,需要從數據庫中返回一個文件。爲此,我創建了兩個MessageContract類,一個用於輸入,另一個用於輸出。代碼如下:WCF代理沒有正確生成
[MessageContract]
public class AttachmentFile
{
[MessageHeader(MustUnderstand = true)]
public Int32 AttachmentID;
[MessageHeader]
public String FileName;
[MessageBodyMember(Order = 1)]
public Stream Data;
public AttachmentFile(Attachment att)
{
AttachmentID = (Int32)att.AttachmentID;
FileName = att.FileName;
Data = new MemoryStream(att.FileBytes);
}
}
[MessageContract]
public class AttachmentFileID
{
[MessageBodyMember]
public Int32 AttachmentID;
}
public AttachmentFile GetAttachmentFile(AttachmentFileID AttachmentID)
{
}
生成WSDL看起來是正確的:
<wsdl:operation name="GetAttachmentFile">
<soap12:operation soapAction="http://tempuri.org/IAttachments/GetAttachmentFile" style="document"/>
<wsdl:input name="AttachmentFileID">
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output name="AttachmentFile">
<soap12:header message="i0:AttachmentFile_Headers" part="AttachmentID" use="literal"/>
<soap12:header message="i0:AttachmentFile_Headers" part="FileName" use="literal"/>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
然而,當我運行svcutil.exe http://localhost:8002/IAttachments?wsdl
,生成的代碼出來的:
public string GetAttachmentFile(ref int AttachmentID, out System.IO.Stream Data)
{
AttachmentFileID inValue = new AttachmentFileID();
inValue.AttachmentID = AttachmentID;
AttachmentFile retVal = ((IAttachments)(this)).GetAttachmentFile(inValue);
AttachmentID = retVal.AttachmentID;
Data = retVal.Data;
return retVal.FileName;
}
我當然,我錯過了一些簡單的東西,但我似乎無法找到它是什麼。有沒有人有任何線索可能導致這種情況?
如果你用'/ wrapped'參數調用'svcutil'會怎麼樣?這將防止「展開」參數(就像在你的情況下發生的那樣)。另外 - 嘗試svcutil上的'/ messageContract'開關告訴它你正在使用一個消息合約 - 有時幫助... –
沒有錯 - 合同是一樣的。你應該可以用這個客戶端調用服務,它應該可以很好地工作。 – carlosfigueira
謝謝。/messagecontract開關有竅門。只要我弄清楚,我會接受你的答案。 carlosfigueira:雖然我知道它在技術上是正確的並且可以工作,但現在它是如何編寫原始通話並且更糟,這並不直觀。我的老闆永遠不會在我們的代碼中接受這樣的電話。 –