繁体   English   中英

从Windows Form和jQuery调用Web服务

[英]Calling web service from Windows Form and jQuery

我有一个现有的Web WCF Web服务,可以通过代理通过Windows窗体调用。

我也希望能够从jQuery调用此服务。

我关注以下文章: http : //www.codemag.com/Article/1308041

但是,我很困惑,因为文章说要将以下代码添加到服务的web.config中:

<services>
  <service
      behaviorConfiguration="ProductServiceBehavior"
      name="ProductServiceHost.ProductService">
    <endpoint
      address=""
      binding="basicHttpBinding"
      contract="ProductServiceHost.IProductService" />
  </service>
</services>

我的配置文件已经为我的服务提供了此服务:

<service 
    behaviorConfiguration="MyApp.EndPoint.Services.TrainingServiceBehavior"    
    name="MyApp.EndPoint.Services.TrainingService">
  <endpoint 
    address="" binding="wsHttpBinding" 
    contract="MyApp.EndPoint.Services.Interface.ITrainingService" 
    name="wsHttp" 
    bindingConfiguration="wsHttpBindingConfiguration">
    <identity>
      <dns value="localhost" />
    </identity>
  </endpoint>
  <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>

我尝试用basicHttpBinding替换绑定,但是从Windows窗体调用服务时出现错误,例如“远程服务器返回错误:(415)不支持的媒体类型。”

我的服务应该同时具有以上两个绑定吗?

基本上,我的更改在以下步骤中失败:您应该在此时运行现有应用程序,以确保一切仍然正常。

谁能指出我正确的方向?

我将以下内容添加到配置文件中:

  <service
      behaviorConfiguration="MyApp.EndPoint.Services.TrainingServiceBehavior"
      name="MyApp.EndPoint.Services.TrainingService">
    <endpoint
      address=""
      binding="basicHttpBinding"
      contract="MyApp.EndPoint.Services.Interface.ITrainingService" />
  </service>

我还添加了以下装饰:

[WebInvoke(Method = "POST", 
BodyStyle = WebMessageBodyStyle.WrappedRequest, 
ResponseFormat = WebMessageFormat.Json, 
RequestFormat = WebMessageFormat.Json)]

但是,我的Windows窗体应用程序现在在调用该服务时收到以下错误:

服务器未提供有意义的回复; 这可能是由于合同不匹配,会话过早关闭或内部服务器错误引起的。

该错误大概是因为我在配置文件中有两个具有相同名称的服务。 如果我给新服务起一个新名称,是否需要创建一个新方法?

我正在尝试使用相同的方法,但这似乎是不可能的。

我认为您可以保留当前配置。 本文中所做的更改是对一个非常基本的配置进行的,以使现有服务的配置变得明确(通过声明绑定,协定和行为)。 您的配置已经明确指出了该服务。

您应该做的是按照文章中的描述为jquery添加一个新配置:添加新行为并添加新端点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM