考虑以下合同
[OperationContract]
[FaultContract(typeof(CcmFaultException))]
void UploadStream(DataFileStream input);`
[MessageContract]
public class DataFileStream
{
[MessageHeader(MustUnderstand = true)]
public String FileName { get; set; }
[MessageHeader(MustUnderstand = true)]
public long FileSize { get; set; }
[MessageBodyMember(Order = 1)]
public Stream StreamData { get; set; }
}
我确实有两个主要问题。
第一个问题是在服务方面我无法更改UploadStream
签名,当我在接口和相关类中更改方法签名时(例如添加返回类型或更多输入参数),我可以构建服务但是当我运行主机应用程序时,我收到以下错误:
[System.InvalidOperationException]
操作UploadStream要么具有参数,要么具有与MessageContractAttribute一起归属的返回类型 为了使用消息合同表示请求消息,操作必须具有一个归属于...的单个参数
另一个问题是在客户端,即使我使用UploadStream(DataFileStream data)
合同
我可以创建一个DataFileStream
类的对象,但是当我想调用UploadStream
方法时,我无法传递该对象!我看到的唯一选择是客户端的以下签名:
UploadStream(string FileName, long FileSize, Stream StreamData);
请你帮我解决这两个问题。
谢谢
P.S:我使用以下配置:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="CCMService.Binding_ICcmWcfService" closeTimeout="00:10:00"
openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
maxReceivedMessageSize="2147483647">
<reliableSession ordered ="false" inactivityTimeout ="00:05:00"
enabled ="true" />
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName"
negotiateServiceCredential="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://localhost:8731/CCMService"
binding="wsHttpBinding"
bindingConfiguration="CCMService.Binding_ICcmWcfService"
contract="CCMServiceRef.ICcmWcfService"
name="CCMService.Binding_ICcmWcfService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
答案 0 :(得分:0)
@ Steve16351
考虑客户端应用程序中的以下实现
private void btnImport_Click(object sender, EventArgs e)
{
CCMServiceRef.DataFileStream obj = new CCMServiceRef.DataFileStream()
{
FileName = _FileName,
StreamData = GetStream(_FilePath)
};
Program.serviceManager.Client.ImportScript(obj);
}
private Stream GetStream(string filePath)
{
System.IO.MemoryStream data = new System.IO.MemoryStream();
System.IO.Stream str = File.OpenRead(filePath);
str.CopyTo(data);
data.Seek(0, SeekOrigin.Begin);
byte[] buf = new byte[data.Length];
data.Read(buf, 0, buf.Length);
return data;
}
当我切换到DataContract程序编译和主机应用程序运行时,但是当我调用Service方法(Program.serviceManager.Client.ImportScript(obj))时,程序会持续几分钟,直到不活动超时提升为止! 实际上,Service方法从未执行过!