Wcf从客户端项目调用问题 [英] Wcf calling problem from client project

查看:124
本文介绍了Wcf从客户端项目调用问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我第一次使用WCf sercive并且我遇到了问题。

当我在界面中创建单个参数请求体时如



Hello i am using WCf sercive 1st time and i have a problem.
When i create single parameter request body in interface like

<pre lang="c#"> [OperationContract]
        string InsertSurvey (string Templatename);





和cs页面中的



and in cs page like

public string InsertSurvey(string Templatename){}



它工作正常,但是当我添加多个周长时,例如




it's working fine, but when i add multiple perimeters like

<pre lang="c#"> [OperationContract]
        int UpdateSyrvey(string SurveyID, string Templatename);



和cs页面中的


and in cs page like

public int UpdateSyrvey(string SurveyID,string Templatename)



i我收到错误


i am getting error

Operation 'UpdateSyrvey' of contract 'ISurveyUserManagmentApi' specifies multiple request body parameters to be serialized without any wrapper elements. At most one body parameter can be serialized without wrapper elements. Either remove the extra body parameters or set the BodyStyle property on the WebGetAttribute/WebInvokeAttribute to Wrapped.



i我不明白我错在哪里。

我的配置文件是




i am not understand where i am wrong .
and my config file is

<pre>
      <service  behaviorConfiguration="defaultBehavior" name="CheckboxWeb.Api.SurveyUserManagmentApi">
        <host>
          <baseAddresses>
            <add baseAddress="[CHECKBOX_ROOT]/Api" />
          </baseAddresses>
        </host>
        <!--<endpoint address="" contract="CheckboxWeb.Api.ISurveyUserManagmentApi" binding="basicHttpBinding" />
        <endpoint address="mex" contract="IMetadataExchange" binding="mexHttpBinding" />-->
        <endpoint address="soap" binding="basicHttpBinding" bindingConfiguration="soapBinding" contract="CheckboxWeb.Api.ISurveyUserManagmentApi" />
        <endpoint address="pox" behaviorConfiguration="poxBehavior" binding="webHttpBinding" bindingConfiguration="webBindingPox" contract="CheckboxWeb.Api.ISurveyUserManagmentApi" />
        <endpoint address="json" behaviorConfiguration="jsonBehavior" binding="webHttpBinding" bindingConfiguration="webBindingJson" contract="CheckboxWeb.Api.ISurveyUserManagmentApi" />
        <!--<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />-->
        <endpoint address="mex" contract="IMetadataExchange" binding="mexHttpBinding" />
      </service>



请帮帮我



我的尝试:



在Google中查找但不是低估。未找到示例代码


pls help me

What I have tried:

Find in google but not understating. No sample code found

推荐答案

use in  IService page 




[OperationContract]
      [WebInvoke(UriTemplate = "Login",
           Method = "POST",
           ResponseFormat = WebMessageFormat.Json,
            RequestFormat = WebMessageFormat.Json,
           BodyStyle = WebMessageBodyStyle.WrappedRequest)]
      [WebGet(UriTemplate = "Login/{UserName}/{Password}")]



或者


or

[OperationContract]
      [WebInvoke(UriTemplate = "Login",
           Method = "POST",
           ResponseFormat = WebMessageFormat.Json,
            RequestFormat = WebMessageFormat.Json,
           BodyStyle = WebMessageBodyStyle.WrappedRequest)]
      ResponseModel<UserBase> Login(string UserName = null, string Password = null);
















use in  Service page 










public ResponseModel<UserBase> Login(string UserName, string Password)
     {
         ResponseModel<UserBase> responseModel = new ResponseModel<UserBase>();
         try
         {
             using (var context = new Entities())
             {
                 User user = context.Users.Where(m => m.UserName == UserName && m.Password == Password).FirstOrDefault();
                 if (user != null)
                 {
                     UserBase userInfo = Utility.CommonFunctions.Cast<AutoPOS.Base.UserInfo.UserBase>(user);
                     userInfo.UserInRoles = new List<AutoPOS.Base.UserInfo.UserInRole>();
                     foreach (var item in user.UserInRoles)
                     {
                         AutoPOS.Base.UserInfo.UserInRole userInRole = Utility.CommonFunctions.Cast<AutoPOS.Base.UserInfo.UserInRole>(item);
                         userInRole.RoleMaster = Utility.CommonFunctions.Cast<AutoPOS.Base.RoleMaster.RoleMaster>(item.RoleMaster);
                         userInRole.RoleMaster.MenuPermissions = new List<Base.UserInfo.MenuPermission>();
                         foreach (var menuPermissions in item.RoleMaster.MenuPermissions)
                         {
                             Base.UserInfo.MenuPermission menuPermission = Utility.CommonFunctions.Cast<AutoPOS.Base.UserInfo.MenuPermission>(item);
                             menuPermission.MenuMaster = Utility.CommonFunctions.Cast<AutoPOS.Base.MenuMaster.MenuMaster>(menuPermissions.MenuMaster);
                             userInRole.RoleMaster.MenuPermissions.Add(menuPermission);
                         }
                         userInfo.UserInRoles.Add(userInRole);
                     }

                     responseModel.Status = 1;
                     responseModel.Data = userInfo;
                     responseModel.Message = "Success";
                 }
                 else
                 {
                     responseModel.Status = -1;
                     responseModel.Data = new UserBase();
                     responseModel.Message = "Error";
                 }
             }

         }
         catch (Exception ex)
         {
             responseModel.Status = -1;
             responseModel.Data = new UserBase();
             responseModel.Message = "Error";
         }
         return responseModel;
     }


这篇关于Wcf从客户端项目调用问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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