简体   繁体   English

如何在服务asmx中使用服务引用?

[英]How to use service reference in a service asmx?

I'm new to C# and asp.net, but i will try to explain as good as i can. 我是C#和asp.net的新手,但我将尽我所能解释。

I want to add a service reference from http://www8.something.com/service1.asmx to a service called localhost/WeatherParser.asmx in which I could use the methods from the service1.asmx. 我想从http://www8.something.com/service1.asmx将服务引用添加到名为localhost/WeatherParser.asmx的服务中,在其中可以使用service1.asmx中的方法。

I have tried adding service reference to my default.aspx like mentioned here and it worked ok, but how do i use a service in another service ? 我已经尝试将服务引用添加到此处提到的default.aspx并且工作正常,但是如何在另一个服务中使用服务?

Is it even possible and how ? 甚至有可能吗? Please give some - Explanations,examples and reference to another sources. 请提供一些-说明,示例并参考其他来源。

What it looks like in my head: 在我的脑海中是什么样的:

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

If there are some other ways than I were able to think of please share. 如果有我无法想到的其他方法,请分享。

Thanks in advance! 提前致谢!

So first you create the Web service that you would like to use 因此,首先您要创建要使用的Web服务

[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";
    }
}

I am not sure how to call the web method in C# but here it is in JavaScript 我不确定如何在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); 
        }
    });         
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM