gpt4 book ai didi

asp.net - 从另一台服务器调用Web服务

转载 作者:行者123 更新时间:2023-12-01 05:57:19 25 4
gpt4 key购买 nike

我创建了一个名为 MailSerderWS.asmx 的 Web 服务,其代码位于 AppCode/MailSerderWS.cs 中,它在本地 PC 上工作正常,但我有一些关于它在生产中的用法:

  1. 基本上我正在创建这个服务从我的服务器发送电子邮件,因为我的服务器不支持asp,所以不能使用编码,所以我计划将网络服务放在我 friend 的服务器上并调用网络服务从我的服务器发送邮件网站。
  2. 在我的 friend 服务器上部署此 Web 服务之前,我想使用我的 html 网页在我的本地计算机上检查此 Web 服务。下面是我正在运行的jquery。但它从不回发,因此不会将邮件发送到我的收件箱。
  3. 我如何才能在我 friend 的实时服务器上上传这个网络服务,以便我可以在我的html页面中使用这个网络服务以及我将如何使用它,因为我想如果我使用上面的ajax它永远不会执行的方法

第 2 项代码:

$("#btnSendMail").click(function(){
$.ajax({
type: "POST",
url: "http://audiomedia.dev.asentechdev1.com/MailSenderWS.asmx/SendMail",
data: "{'sendermail':'aelectricwala52@gmail.com', 'type':'standalone app', 'body':'success'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
alert(msg)
},
error: function(msg){
alert(msg.responseText);
}
});
})

提前致谢。

最佳答案

我看到两个语法错误。试试这个:

$("#btnSendMail").click(function(){
$.ajax({
type: "POST",
url: "http://localhost:16189/MailSenderWS.asmx/SendMail",
data: "{'sendermail':'aelectricwala52@gmail.com', 'type':'standalone app', 'body':'success'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
alert(msg)
},
error: function(msg){
alert(msg);
}
});
});

不久前,我写了一篇关于 asmx webservice 方法并从 Jquery 调用它的文章。这可能对您有帮助:http://www.tomot.de/en-us/article/8/asp.net/how-to-use-jquery-to-call-a-webservice-asmx-method

编辑:根据您的更新,我尝试通过 Ajax 调用它,但这对我来说也不起作用。该服务似乎已正确部署,因为您可以在浏览器中调用该 URL。我将您的服务添加为服务引用,调用您的方法并使用 Fiddler捕获通信。

连接到服务器没有问题,但是服务的响应表明与您的电子邮件帐户相关的身份验证问题:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<SendMailResponse xmlns="http://tempuri.org/">
<SendMailResult>
Fail Reason: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. sk1sm6949585pbc.0
</SendMailResult>
</SendMailResponse>
</soap:Body>
</soap:Envelope>

尝试在不使用 Web 服务的情况下从本地计算机发送电子邮件,看看是否可以正常工作。然后重新部署,您就可以开始了。
我还建议您更改网络服务的 URL,因为现在您已将其发布到网上并且不涉及身份验证,有人可能会滥用它。

编辑2:我会告诉你我是如何使用Fiddler的。首先您需要下载并安装它。

创建一个新的.net应用程序(例如ConsoleApplication)。在解决方案资源管理器中,右键单击该项目,然后单击添加服务引用。使用 URL http://audiomedia.dev.asentechdev1.com/MailSender.asmx

这会在您的项目中生成一些代码。

启动 Fiddler 并在 ConsoleApplication 中执行此代码(根据生成的名称,您需要调整此示例):

    ServiceReference1.MailSenderSoapClient client = new ServiceReference1.MailSenderSoapClient();
client.SendMail();

在 Fiddler 中,您将在左侧站点上看到 Web session 。已添加包含您的网址的新条目。点击它。在底部区域的右侧视线中,您会看到消息

Response is encoded and may need to be decoded before inspection. Click here to transform.

如果您单击该消息并选择 TextView TabPage,您将从服务中获得以下结果:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<SendMailResponse xmlns="http://tempuri.org/">
<SendMailResult>Success</SendMailResult>
</SendMailResponse>
</soap:Body>
</soap:Envelope>

关于asp.net - 从另一台服务器调用Web服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14308055/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com