当客户端代理被保存 [英] where the client proxy be saved

查看:163
本文介绍了当客户端代理被保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加Web引用到WCF服务

我要修改的代理文件由Web服务的参考工具自动生成的。

我想每个方法atttribute前添加像

  [OperationContract的]
[WebInvoke(方法=GET,
ResponseFormat = WebMessageFormat.Json,BodyStyle = WebMessageBodyStyle.Wrapped,UriTemplate =登录/ {用户名} / {}密码)]

任何想法如何做到这一点。

最好的问候


解决方案

您好:

我加入这一点,因为职以上没有真正清楚如何添加WebInvoke在客户端代理code属性,所以我使这适用于清除任何混乱,它的工作原理。

步骤1

去你的VS项目文件夹,找到你的服务引用文件夹。查找您所使用的参考文件夹,如果使用默认的时添加服务,则应该像ServiceReference1。

在该文件夹那里有一个Reference.cs文件,那你为了更新您的方法需要的人。

因此​​,例如,可以说您创建了一个REST的服务与您WebInvoke属性被排斥在外。你可以只添加它们在那里。

步骤2

只要找到与[System.ServiceModel.OperationContractAttribute开头的行:

应该是这个样子。

<$p$p><$c$c>[System.ServiceModel.OperationContractAttribute(Action=\"http://tempuri.org/IService1/YourMethodName\", ReplyAction =htt​​p://tempuri.org/IService1/YourMethodNameResponse)]

步骤3

现在您要添加的WebInvoke code像这样的行之后:

<$p$p><$c$c>[System.ServiceModel.OperationContractAttribute(Action=\"http://tempuri.org/IService1/YourMethodName\", ReplyAction =htt​​p://tempuri.org/IService1/YourMethodNameResponse)][System.ServiceModel.Web.WebInvoke(方法=POST,BodyStyle = System.ServiceModel.Web.WebMessageBodyStyle.WrappedRequest,RequestFormat = System.ServiceModel.Web.WebMessageFormat.Json,ResponseFormat = System.ServiceModel.Web.WebMessageFormat.Json ,UriTemplate =/ YourMethodName)]

这就是所有孤单吧。

注意:万一你删除WCF服务引用您所做的更改将会消失。因此,请确保您的备份文件完成后进行更改后。

I add web reference to WCF service

I want to modify the proxy file be automatically generated by the web service reference tool

I want to add before each method atttribute like

[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,

BodyStyle = WebMessageBodyStyle.Wrapped,

UriTemplate = "LogIn/{username}/{password}")]

any idea how to do that

Best regards

解决方案

Hi there:

I'm adding this since the post above didn't really made it clear how to add WebInvoke attributes in client proxy code so I'm making this available to clear any confusion as to how its done.

STEP 1

Go To your VS Project Folder and Locate your "Service References" Folder. Find the Reference folder you are using, if you used default one when adding the Service then should be something like "ServiceReference1".

Inside that folder theres a Reference.cs file, thats the one you need in order to update your methods.

So for example lets say you created a REST Service and your WebInvoke attributes were left out. You can just add them there.

STEP 2

Just find the line that starts with "[System.ServiceModel.OperationContractAttribute":

Should look something like this

[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IService1/YourMethodName", ReplyAction="http://tempuri.org/IService1/YourMethodNameResponse")]

STEP 3

Now after that line you want to add your WebInvoke code like this:

[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IService1/YourMethodName", ReplyAction="http://tempuri.org/IService1/YourMethodNameResponse")]

[System.ServiceModel.Web.WebInvoke(Method = "POST", BodyStyle = System.ServiceModel.Web.WebMessageBodyStyle.WrappedRequest, RequestFormat = System.ServiceModel.Web.WebMessageFormat.Json, ResponseFormat = System.ServiceModel.Web.WebMessageFormat.Json, UriTemplate = "/YourMethodName")]

Thats all theres to it.

NOTE: If by any chance you delete your WCF service reference the changes you made will be gone. So make sure you backup the file after you are done making changes to it.

这篇关于当客户端代理被保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆