【问题标题】:How to use service reference in a service asmx?如何在服务 asmx 中使用服务引用?
【发布时间】:2017-01-04 19:26:25
【问题描述】:

我是 C# 和 asp.net 的新手,但我会尽量解释清楚。

我想将来自http://www8.something.com/service1.asmx 的服务引用添加到名为localhost/WeatherParser.asmx 的服务中,我可以在其中使用service1.asmx 中的方法。

我已经尝试将服务引用添加到我的default.aspx,就像提到的here 一样,它工作正常,但是我如何在另一个服务中使用服务?

这是否可能以及如何实现?请给出一些解释、例子和对其他来源的参考。

它在我脑海中的样子:

DefaultApp < Weatherservice.aspx < Servicereference(http://www8.something.com/service1.asmx)

如果有其他我能想到的方法,请分享。

提前致谢!

【问题讨论】:

  • 如果您问is it possible to call web service from another web service?,答案是:是的,根据this。而this 应该可以帮助您了解如何做到这一点。

标签: c# asp.net web-services wcf soap


【解决方案1】:

所以首先你要创建你想使用的网络服务

[WebService(Namespace = "http://tempuri.org/")]
public class MyWebService{
    public string RunCodeThroughWebService()
    {
        //Do some stuff to the server or whatever you want to do
        return "Hello World";
    }
}

我不知道如何在 C# 中调用 web 方法,但这里是在 JavaScript 中

function runWebService{
    $.ajax({
        url: '/webservices/MyWebService.asmx/RunCodeThroughWebService',
        data: { },
        type: 'POST',
        dataType: 'string',
        timeout: 50000,
        error: function(){  

        },
        success: function(result){              
            $('body').html(result); 
        }
    });         
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-23
    • 2016-11-03
    • 1970-01-01
    • 2013-04-10
    • 1970-01-01
    • 2012-04-16
    • 1970-01-01
    • 2016-02-09
    相关资源
    最近更新 更多