是否可以让 WCF 服务也作为 Web 服务客户端执行?
如果这是可能的,你能给我一些关于如何在配置文件中配置客户端设置的指导吗?
我遇到的主要问题是我正在向我的主要 REST 服务发送大消息。当该消息被中继到辅助服务时,响应似乎触发了“MaxReceivedMessage”过大错误。我尝试为我的 REST 服务配置 CLIENT 设置,但没有成功。
我在 app.config 或 web.config 中定义哪个配置?
似乎我做错了,因为无论我在哪里声明客户端设置,绑定都会被忽略。
这是我的 REST 服务的应用程序配置。
<?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>
这是我的 REST 服务上失败的端点方法:
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);
}
}