C# 如何使用WCF服务连接Microsoft Dynamic CRM帐户?

C# 如何使用WCF服务连接Microsoft Dynamic CRM帐户?,c#,wcf,dynamics-crm,C#,Wcf,Dynamics Crm,我想使用服务器上托管的WCF服务连接Microsoft Dynamic CRM帐户。目前,如果我在IIS服务器中托管服务,我可以连接到它,但当我将服务托管到我们的服务器时,我无法连接 以下是我为理解而创建的示例: <input id="Button1" type="button" value="Get Data from Crm Call" onclick="checkConnection()" /> function checkConnection() { var req

我想使用服务器上托管的WCF服务连接Microsoft Dynamic CRM帐户。目前,如果我在IIS服务器中托管服务,我可以连接到它,但当我将服务托管到我们的服务器时,我无法连接

以下是我为理解而创建的示例:

<input id="Button1" type="button" value="Get Data from Crm Call" onclick="checkConnection()" />

function checkConnection() {
    var requestData = {
        //data of CRM like user name password etc
    };

    //Service call
    try {
        $.ajax({
            type: "POST",
            // url: "http://localhost:13213/Service1.svc/savedata", //this is working fine
            url: "http://mdcportal.biztechconsultancy.com/Service1.svc/savedata/",
            data: JSON.stringify(requestData),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data, status, XMLHttpRequest) {
                debugger;
                //I get success for service call
                alert(data.ResponseData);
            },
            error: function (xhr) {
                alert("error"+xhr.responseText);
            }
        });
    } catch (err) {
        alert(err.message + " Error");
    }
}

函数checkConnection(){
var请求数据={
//CRM的数据,如用户名、密码等
};
//服务电话
试一试{
$.ajax({
类型:“POST”,
//url:“http://localhost:13213/Service1.svc/savedata“,//这很好用
url:“http://mdcportal.biztechconsultancy.com/Service1.svc/savedata/",
数据:JSON.stringify(requestData),
contentType:“应用程序/json;字符集=utf-8”,
数据类型:“json”,
成功:函数(数据、状态、XMLHttpRequest){
调试器;
//我的服务电话成功了
警报(数据响应数据);
},
错误:函数(xhr){
警报(“错误”+xhr.responseText);
}
});
}捕捉(错误){
警报(err.message+“Error”);
}
}
WCF服务

//service call
public class Service1 : IService1
{
    public RequestData authentication(CRMCredential objauthentication)
    {
        //get data successfully from objauthentication
        RequestData result = new RequestData();
        try
        {
            List<PostData> itemlist = new List<PostData>();
            ClientCredentials clientCredentials = new ClientCredentials();
            clientCredentials.UserName.UserName = objauthentication.Username;  //Username;
            clientCredentials.UserName.Password = objauthentication.Password;
            Uri oUri = new Uri(objauthentication.Uri);

            //go to catch from following fine
            _serviceProxy = new OrganizationServiceProxy(oUri, null, clientCredentials, null);

            //few code here to populate other information

        }
        catch (Exception ex)
        {
            result.isSuccess = false;
            CallDetails objcalldetail = new CallDetails();
            objcalldetail.code = ex.ToString();
            objcalldetail.message = "CRM authentication failed";
            result.CallDetail = objcalldetail;
        }
        return result;
    }
}
//服务调用
公共类服务1:IService1
{
公共请求数据身份验证(CRMCredential对象身份验证)
{
//成功从对象身份验证获取数据
RequestData结果=新的RequestData();
尝试
{
List itemlist=新列表();
ClientCredentials ClientCredentials=新的ClientCredentials();
clientCredentials.UserName.UserName=objauthentication.UserName;//用户名;
clientCredentials.UserName.Password=objauthentication.Password;
Uri-oUri=新Uri(objauthentication.Uri);
//从后面去抓罚款
_serviceProxy=新组织serviceProxy(oUri,null,clientCredentials,null);
//这里几乎没有填充其他信息的代码
}
捕获(例外情况除外)
{
result.issucess=false;
CallDetails objcalldetail=newcalldetails();
objcalldetail.code=ex.ToString();
objcalldetail.message=“CRM身份验证失败”;
result.CallDetail=objcalldetail;
}
返回结果;
}
}
错误:

请注意,如果我可以尝试通过在IIS中托管wcf服务进行连接,那么它工作正常


如果我遗漏了什么,请建议我。

您说“如果我在IIS服务器上托管我的服务,当前我可以连接到它,但当我将我的服务托管到我们的服务器时,我无法连接”,您所说的“将我的服务托管到我们的服务器”是什么意思你是说从iis托管的机器本地运行还是托管在iis托管的服务器上?@MattDearing是的。当我在我系统的IIS中运行该服务时,它工作得非常好。但当我将服务托管到我们的服务器时(我们有一个托管所有服务的服务器),它会抛出上述错误。因此,在您的机器上,它在IIS中运行,在服务器上,它作为独立服务托管?@MattDearing我很抱歉,但我不明白您的要求。让我给你解释一下。我已在hostgator中托管了服务。但它抛开了错误。因此,我尝试在本地系统的IIS服务器上托管该服务,效果良好。如果您仍有查询,请告诉我。根据评论,我猜测hostgator的权限/信任级别低于您在本地运行的权限/信任级别。不确定您是否可以在这里执行任何操作。您说“如果我在IIS服务器上托管我的服务,当前我可以连接到它,但当我将我的服务托管到我们的服务器时,我无法连接”,您所说的“将我的服务托管到我们的服务器”是什么意思你是说从iis托管的机器本地运行还是托管在iis托管的服务器上?@MattDearing是的。当我在我系统的IIS中运行该服务时,它工作得非常好。但当我将服务托管到我们的服务器时(我们有一个托管所有服务的服务器),它会抛出上述错误。因此,在您的机器上,它在IIS中运行,在服务器上,它作为独立服务托管?@MattDearing我很抱歉,但我不明白您的要求。让我给你解释一下。我已在hostgator中托管了服务。但它抛开了错误。因此,我尝试在本地系统的IIS服务器上托管该服务,效果良好。如果您仍有查询,请告诉我。根据评论,我猜测hostgator的权限/信任级别低于您在本地运行的权限/信任级别。我不确定你能在这里做什么。