解决方案 »

  1.   

    LoginResponseBDU 有定义数据契约吗
      

  2.   

    有啊,只不过代码没贴出来,我用json的时候一切正常using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ServiceModel;
    using System.ServiceModel.Web;
    using System.Runtime.Serialization;namespace ARTWcf.BusinessEntity.Login
    {
        [DataContract]
        public class LoginRequestBDU
        {
            private string _userid = "";
            private string _password = "";
            private Int16 _deviceType;        [DataMember]
            public string userid
            {
                get;
                set;
            }        [DataMember]
            public string password
            {
                get;
                set;
            }        [DataMember]
            public Int16 deviceType
            {
                get;
                set;
            }        public LoginRequestBDU()
            {
     
            }
        }
    }
      

  3.   

    什么错误都没报,json的都能传参和返回值,xml的前台能接收返回数据,但是参数传不过去,我不知道xml应该如何传参,我这样写估计肯定是不对的
      

  4.   

    我照你的原文作了修改可以显示的哇,你对照看一下,如果还不能显示查看一下是不是跨域了,
    namespace WcfService1
    {
        [ServiceContract]   
        public interface ILog
        {
            [OperationContract]
            [WebGet(ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml)]
            List<LoginResponseBDU> Login(string userid, string password);
        }
        [DataContract]
        public class LoginResponseBDU
        {
            [DataMember]
            public string userid
            {
                get;
                set;
            }        [DataMember]
            public string password
            {
                get;
                set;
            }        [DataMember]
            public Int16 deviceType
            {
                get;
                set;
            }       
        }
    }namespace WcfService1
    {
     
      
        [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
        public class Log : ILog
        {
            public List<LoginResponseBDU> Login(string userid, string password)
            {
               // LoginDAL loginDAL = new LoginDAL();
                List<LoginResponseBDU> ResponseList = new List<LoginResponseBDU>();
              //  int status = loginDAL.Login(userid, password, out ResponseList);
                ResponseList.Add(new LoginResponseBDU() {userid=userid,password=password });
                return ResponseList;
            }
        }}
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <system.web>
        <compilation debug="true" targetFramework="4.0" />
      </system.web>
      <system.serviceModel>
        <services>
          <service name="WcfService1.Log">
            <endpoint behaviorConfiguration="Ajaxor"  binding="webHttpBinding" contract="WcfService1.ILog"/>
          </service>
        </services>
        <behaviors>
          <endpointBehaviors>
            <behavior name="Ajaxor">
              <enableWebScript/>
            </behavior>       
          </endpointBehaviors>
          <serviceBehaviors>
            <behavior>
              <!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点 -->
              <serviceMetadata httpGetEnabled="true"/>
              <!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息 -->
              <serviceDebug includeExceptionDetailInFaults="true"/>  
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true"  aspNetCompatibilityEnabled="true"/>
      </system.serviceModel>
     <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
      </system.webServer>  
    </configuration>jq
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js">
    </script></head>
     <script type="text/javascript">
            $(document).ready(function() {
                $('#GetUser').click(function() {

     $.ajax({
                     type: "get",
                      url: "http://localhost:31162/Service1.svc/Login",
                     data:"userid=user_sssaaa&password=bbbd",
      dataType: "xml",   
                       success: function (employees) {
         
      $(employees).find("LoginResponseBDU").each(function () {
                            $strUser = $(this);
                            User = $strUser.find("userid").text();
    $("#showname").text("用户名:"+User);
                        })
                         
                      },
      error:function(a,b,c){alert(c);}
      
                   });            });
               
            });
       </script>
    <body>       <p id="GetUser">GetUser</p>
           <p id="showname" style="font-size:20px; background-color:#ffccff">&nbsp;</p>
       
       
    </body>
    </html>svc
    <%@ ServiceHost Language="C#" Debug="true" Service="WcfService1.Log" CodeBehind="Service1.svc.cs" %>
      

  5.   

    跨域的话得在config里加 <webHttpBinding>
            <binding crossDomainScriptAccessEnabled="true" />
         </webHttpBinding>
      

  6.   

    如果你解决了,得给我加几分啊,因为刚才service name="WcfService1.Log"不小心写错调试了半个多小时
      

  7.   

    什么都没有错!!! 
    就是错在直接使用 JSON 对象传递给服务方法:
    正确做法是: 
        var newp = {};
        newp.id = 299;
        newp.first_name = "Sha";
        newp.last_name = "Zhang";
        newp.country = "USA";    $.ajax({
            data: JSON.stringify(newp),
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            success: function (req, tStatus) {
                alert(req);
            },
            type: "POST",
            url: "http://xxxxxxx/xxxxx"
        });
      

  8.   

    什么错误都没报,json的都能传参和返回值,xml的前台能接收返回数据,但是参数传不过去,我不知道xml应该如何传参,我这样写估计肯定是不对的 一般XML网络间传值,如WS,或是WCF都建议BASE64后进行传。