简体   繁体   English

ASP.Net和Web服务

[英]ASP.Net and Web Services

I have been searching for 4 days non stop. 我一直在寻找4天不间断。 I am sleep deprived and going crazy. 我被剥夺了睡眠,快要疯了。 Can someone please help me or at least tell me what I'm doing wrong. 有人可以帮我还是至少告诉我我做错了什么。 This is my project Develop a client web page app that uses the web service found at http://www.marksmerry.com/peanutbutter/WebService1.asmx . 这是我的项目,开发一个使用位于http://www.marksmerry.com/peanutbutter/WebService1.asmx的Web服务的客户端网页应用程序。 The service generates a random number m This service receives a guess , an integer between 1-100 inclusive. 该服务生成一个随机数m该服务接收一个guess,一个介于1到100之间的整数。 It returns a string: 它返回一个字符串:

  • low - if the guess is lower than m 低-如果猜测值小于m
  • equal – if the guess is correct 相等–如果猜测正确
  • high - if the guess is higher than m 高-如果猜测高于m

I have referenced the web service but I'm lost at the syntax or something please help me! 我已经引用了Web服务,但语法不知所措,请帮帮我! This is what I have so far. 到目前为止,这就是我所拥有的。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using localhost;
using System.Web.Services;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        localhost.WebService1 ws1 = new WebService1();
        //What goes in this area. I have been searching and have tried all kinds of combination all have resulted in build errors


    }
}

type ws1. 键入ws1。 and a list of methods will appear. 并显示方法列表。

any service methods that were discovered by visual studio when you referenced the 'peanutbutter' webservice will be available to call on the proxy class (called WebService1 in your code example). 当您引用“ peanutbutter” Web服务时,Visual Studio发现的任何服务方法都可以调用代理类(在代码示例中称为WebService1)。

If you just type the url in the browser, it wil show you what methods it has. 如果仅在浏览器中键入URL,它将向您显示它具有的方法。

http://www.marksmerry.com/peanutbutter/WebService1.asmx http://www.marksmerry.com/peanutbutter/WebService1.asmx

I can see a web method Guess which takes an int. 我可以看到一个Guess的网络方法需要一个int。

As per your code, You can call it via 根据您的代码,您可以通过

string result = ws1.Guess(10); // or input 

string result = ws1.Guess(42);

When you added the reference you should have got the chance to give it a name. 添加参考后,您应该有机会为其命名。 It's only semantics but it might be better to give it a different name from localhost. 这只是语义,但给它一个不同于localhost的名称可能会更好。

Previous commentators have made good suggestions so I'd follow them. 以前的评论员提出了很好的建议,因此我将遵循它们。

Only thing I'd suggest is this. 我唯一建议的就是这个。

string result = ws1.Guess("10"); 字符串结果= ws1.Guess(“ 10”); //EDIT: this is wrong of course. //编辑:这当然是错误的。 It takes an int. 它需要一个int。

I did some work this morning using a web service. 我今天早上使用网络服务做了一些工作。

myCoService.Service1 v24 = new myCoService.Service1(); myCoService.Service1 v24 =新的myCoService.Service1();

System.Xml.XmlNode doc = v24.CreateSite(newSiteName); System.Xml.XmlNode doc = v24.CreateSite(newSiteName);

Should be as simple as that. 应该就这么简单。

If it isn't I'd have a look again at how you set up your web reference. 如果不是,我将再次查看您如何设置网络参考。 Also please let us know what NET framework you are using. 另外,请让我们知道您正在使用什么.NET框架。

I added a web Reference to a test project and a button on a page which fires this event. 我在测试项目中添加了Web参考,并在页面上触发了此事件的按钮。

    protected void PeanutGuess_click(object sender, EventArgs e) {
        PeanutButter.WebService1 pb = new PeanutButter.WebService1();

        string response = pb.Guess(10);

        lblResult.Text = string.Format("Response for 10 is " + response);
    }

This works fine for me. 这对我来说很好。 I'm using VS2010 and the project uses Net Framework 3.5 我正在使用VS2010,该项目使用的是Net Framework 3.5

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

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