略晚,我看见,但由于没有答复,我也遇到了类似的问题:
我唯一能够使用一个窗口,即利用从一个交叉客户处获得的窗口,即通过代理人打电话。 别无选择,但现在我不再依赖JSONP。 这项服务由两个终点站、肥皂和json组成——我把整个服务单元放在底层供参考。
因此,客户(所有网络数据)要么:
A. 采用页数方法(或MVC控制器方法)计算出1美元,将周转基金称为网点:
function EmployeeSearch() {
var searchname = $("#userSearchText").val();
if (searchname.length > 0) {
var d = { name: searchname, pageSize: _pageSize, page: _currentPage };
var jsonData = JSON.stringify(d);
if (json.length > 0) {
$.ajax({
type: "POST",
url: "Home/EmployeeSearch",
data: jsonData,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: employeeSearchSuccess,
error: onError
});
}
}
}
以及控制器方法(或页面方法):
[HttpPost]
public ActionResult EmployeeSearch(string name, int pageSize, int page)
{
var client = new EmployeeServiceClient();
var searchResult = client.EmployeeSearch(name);
var count = searchResult.Count();
var employees = searchResult.Skip((page - 1) * pageSize).Take(pageSize).ToList();
var viewModel = new EmployeeSearchViewModel
{
Employees = employees,
Size = count
};
return Json(viewModel);
}
页: 1
B) 向HttpHandler支付一笔钱,如Dave Wards所描述的:
在上述例子中,网络中心。 DownoadString()在手工艺处理方法中将采用下列尿素:
这两种办法都使我的服务保持在窗户之下,客户有两种获得服务的手段。 令人痛心的是,但我不想想。
这里还有整个世界合作框架服务模式,供参考:
<behaviors>
<serviceBehaviors>
<behavior name="EmployeeServiceBehavior">
<serviceTimeouts transactionTimeout="01:00:00"/>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
<!-- we d use this one if we wanted to ignore the d wrapper around the json result ... we don t -->
<endpointBehaviors>
<!-- plain old XML -->
<behavior name="poxBehavior">
<webHttp helpEnabled="true" />
</behavior>
<!-- JSON -->
<behavior name="jsonBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="basicBinding"
hostNameComparisonMode="StrongWildcard"
receiveTimeout="00:10:00"
sendTimeout="00:10:00"
openTimeout="00:10:00"
closeTimeout="00:10:00"
maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647"
maxBufferPoolSize="524288"
transferMode="Buffered"
messageEncoding="Text"
textEncoding="utf-8"
bypassProxyOnLocal="false"
useDefaultWebProxy="true" >
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<!-- use the following for windows authentication -->
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
<webHttpBinding>
<binding name="webBinding"
receiveTimeout="00:10:00"
sendTimeout="00:10:00"
openTimeout="00:10:00"
closeTimeout="00:10:00"
maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647"
maxBufferPoolSize="524288"
bypassProxyOnLocal="false"
useDefaultWebProxy="true"
>
<!--crossDomainScriptAccessEnabled="true"-->
<!-- use the following for windows authentication -->
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</webHttpBinding>
</bindings>
<services>
<service name="EmployeeService.Wcf.EmployeeService" behaviorConfiguration="EmployeeServiceBehavior">
<endpoint address="Soap" binding="basicHttpBinding" bindingConfiguration="basicBinding" contract="EmployeeService.Wcf.IEmployeeService"/>
<endpoint address="Json" binding="webHttpBinding" bindingConfiguration="webBinding" behaviorConfiguration="poxBehavior" contract="EmployeeService.Wcf.IEmployeeService" />
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"/>
一项补充——上文样本方法的业务合同按服务合同规定如下:
[OperationContract]
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "EmployeeSearch/{name}")]
List<Employee> EmployeeSearch(string name);