[英]Calling web service from Windows Form and jQuery
I have an existing web WCF web service which can be called by a Windows form via a proxy. 我有一个现有的Web WCF Web服务,可以通过代理通过Windows窗体调用。
I wish to also be able to call this service from jQuery. 我也希望能够从jQuery调用此服务。
I am following the following article: http://www.codemag.com/Article/1308041 我关注以下文章: http : //www.codemag.com/Article/1308041
However, I am stuck because the article says to add the following code to the web.config of the service: 但是,我很困惑,因为文章说要将以下代码添加到服务的web.config中:
<services>
<service
behaviorConfiguration="ProductServiceBehavior"
name="ProductServiceHost.ProductService">
<endpoint
address=""
binding="basicHttpBinding"
contract="ProductServiceHost.IProductService" />
</service>
</services>
My config file already has this for my service: 我的配置文件已经为我的服务提供了此服务:
<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>
I've tried replacing the binding with the basicHttpBinding, but I then get errors when calling the service from my Windows form, such as "The remote server returned an error: (415) Unsupported Media Type." 我尝试用basicHttpBinding替换绑定,但是从Windows窗体调用服务时出现错误,例如“远程服务器返回错误:(415)不支持的媒体类型。”
Should my service have both of the above bindings? 我的服务应该同时具有以上两个绑定吗?
Basically, my changes fail at the step: You should run your existing application at this point to ensure that everything still works. 基本上,我的更改在以下步骤中失败:您应该在此时运行现有应用程序,以确保一切仍然正常。
Can anyone point me in the right direction? 谁能指出我正确的方向?
I added the following to the config file: 我将以下内容添加到配置文件中:
<service
behaviorConfiguration="MyApp.EndPoint.Services.TrainingServiceBehavior"
name="MyApp.EndPoint.Services.TrainingService">
<endpoint
address=""
binding="basicHttpBinding"
contract="MyApp.EndPoint.Services.Interface.ITrainingService" />
</service>
I also added the following decoration: 我还添加了以下装饰:
[WebInvoke(Method = "POST",
BodyStyle = WebMessageBodyStyle.WrappedRequest,
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json)]
However, my Windows form app now gets the following error when it calls the service: 但是,我的Windows窗体应用程序现在在调用该服务时收到以下错误:
The server did not provide a meaningful reply; 服务器未提供有意义的回复; this might be caused by a contract mismatch, a premature session shutdown or an internal server error.
这可能是由于合同不匹配,会话过早关闭或内部服务器错误引起的。
The error is presumably because I have two services in the config file with the same name. 该错误大概是因为我在配置文件中有两个具有相同名称的服务。 If I give the new service a new name, would I have to create a new method?
如果我给新服务起一个新名称,是否需要创建一个新方法?
I'm trying to use the same method, but this seems to be impossible. 我正在尝试使用相同的方法,但这似乎是不可能的。
I think you can leave your current configuration as it is. 我认为您可以保留当前配置。 The changes made in the article are made to a very basic configuration in order to make the configuration of the existing service explicit (by stating the binding, the contract and the behavior).
本文中所做的更改是对一个非常基本的配置进行的,以使现有服务的配置变得明确(通过声明绑定,协定和行为)。 Your configuration already states the service explicit.
您的配置已经明确指出了该服务。
What you should do is add a new configuration for jquery to use as described in the article: add a new behavior and add a new endpoint. 您应该做的是按照文章中的描述为jquery添加一个新配置:添加新行为并添加新端点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.