我想使用服务器上托管的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");
}
}
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;
}
}
请注意,如果我可以通过在IIS中托管wcf服务来尝试连接,它工作正常。
如果我错过了什么,请建议我。