Click here to Skip to main content
15,892,965 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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);


and in cs page like
C#
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);

and in cs page like
C#
public int UpdateSyrvey(string SurveyID,string Templatename)

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 am not understand where i am wrong .
and my config file is

C#
<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>

pls help me

What I have tried:

Find in google but not understating. No sample code found
Posted
Updated 20-Aug-18 21:06pm

1 solution

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;
     }
 
Share this answer
 
Comments
Member 13907608 21-Aug-18 3:59am    
Thanks adbul it's working. :)
abdul shakib 21-Aug-18 4:08am    
welcome

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900