是否可以将WCF服务也用作Web服务客户端?
如果可以,您能否就如何在配置文件中配置客户端设置提供一些指导?
我遇到的主要问题是我正在向我的主要REST服务发送大量消息。当该消息被中继到辅助服务时,响应似乎会触发“MaxReceivedMessage”太大的错误。我尝试为我的REST服务配置CLIENT设置但没有成功。
我在app.config或web.config中定义了哪个配置?
似乎我做错了,因为无论我在哪里声明CLIENT设置,都会忽略绑定。
这是我的REST服务的APPLICATION配置。
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IBBIImageWarpService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8080/BBIImageWarp" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IBBIImageWarpService"
contract="ServiceReference1.IBBIImageWarpService" name="BasicHttpBinding_IBBIImageWarpService" />
</client>
</system.serviceModel>
</configuration>
这是我的休息服务失败的终点方法:
public ServiceResponse<DataContracts.BBIImgObject> WarpImage(DataContracts.BBIImgObject imgObject)
{
try
{
writeMessage("converting to JSON");
string JSON = new JavaScriptSerializer().Serialize(imgObject);
BasicHttpBinding binding = new BasicHttpBinding();
//我应该将MAXRECEIVEDMessageSize添加到这个绑定中吗?
EndpointAddress address = new EndpointAddress("http://localhost:8080/BBIImageWarp");
ServiceReference1.BBIImageWarpServiceClient ImgWarpSvc = new ServiceReference1.BBIImageWarpServiceClient(binding, address);
string rslt = ImgWarpSvc.WarpImageJSON(JSON);
DataContracts.BBIImgObject cloneImgObject = new DataContracts.BBIImgObject();
cloneImgObject.Base64EncodedImageData = rslt;
cloneImgObject.BodyTypeID = imgObject.BodyTypeID;
return new ServiceResponse<DataContracts.BBIImgObject>(String.Empty, ServiceResponse<DataContracts.BBIImgObject>.ResponseTypeEnum.BbiSuccess, cloneImgObject);
}
catch (Exception ex)
{
writeMessage(ex.Message);
return new ServiceResponse<DataContracts.BBIImgObject>(ex.Message, ServiceResponse<DataContracts.BBIImgObject>.ResponseTypeEnum.BbiFailure, null);
}
}
答案 0 :(得分:1)
您可以使用相同的二进制文件轻松制作客户端
有关根据您的要求提供的详细信息,请参阅http://msdn.microsoft.com/en-us/library/ms576132(v=vs.110).aspx
对于收到的最大错误,您需要执行以下操作: The max message size quota for incoming messages (65536) ....To increase the quota, use the MaxReceivedMessageSize property
或者来自代码:
WebHttpBinding binding = new WebHttpBinding();
binding.MaxReceivedMessageSize = 2147483647;
同样在客户端也是如此。