我正在使用流畅的NHibernate与WebForms,我正在尝试构建一个页面,我允许用户在他们的个人资料页面上发布状态更新,我使用.asmx WebService将数据发布到数据库,然后返回StatusUpdate实例到jQuery使用的页面.我有几个问题.
1)当我从WebService(我正在测试)返回一个字符串时,首先关闭用户输入其状态的文本框不会清空内容.并且由于即使我通过人工清理文本框并输入其他内容页面也不刷新,它仍然会将之前的状态再次发布到数据库.我该如何解决?
2)其次,当我从Webservice返回StatusUpdate对象时,我无法显示结果.就像我很伤心,我使用jQuery对WebService进行AJX调用.
这是我的代码:
用户个人头像Javascript:
var status1 = $("#statusBox").val();
var userID = $("#MainContent_userID").val();
function SetStatus() {
$.ajax({
type: "POST",
url: "http://localhost/Sports/Services/UserWebService.asmx/SetStatus",
data: '{"status": "' + status1 + '", "userID": "' + userID + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
error: OnError
});
}
function OnSuccess(response) {
$("#statusBox").empty();
$("#MainContent_status").html(response.Status).fadeIn(1000);
}
function OnError(request, status, error) {
alert(request.statusText);
}
Run Code Online (Sandbox Code Playgroud)
网络服务:
[WebService(Namespace = "Sports.Services")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class UserWebService : System.Web.Services.WebService
{
private IUserSession _userSession;
public ISession Session1 …Run Code Online (Sandbox Code Playgroud) 我写了一个看起来像这样的ASMX服务;
namespace AtomicService
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[ScriptService]
public class Validation : WebService
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string IsEmailValid(string email)
{
Dictionary<string, string> response = new Dictionary<string, string>();
response.Add("Response", AtomicCore.Validation.CheckEmail(email).ToString());
return JsonConvert.SerializeObject(response, Formatting.Indented);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用Newtonsoft.Json库来提供JsonConvert.SerializeObject功能.当在Fiddler中调用或通过我的Jquery访问时,我收到此响应:

此警报的代码是:
$(document).ready(function () {
$.ajax({
type: "POST",
url: "http://127.0.0.1/AtomicService/Validation.asmx/IsEmailValid",
data: "{'email':'dooburt@gmail.com'}",
contentType: "application/json",
dataType: "json",
success: function (msg) {
if (msg["d"].length > 0) {
alert("fish");
}
alert("success: " + msg.d);
},
error: function (msg) {
alert("error");
} …Run Code Online (Sandbox Code Playgroud) 我有一些(5年)Delphi(30年帕斯卡)的经验,但在WEB编程方面却没有那么多.我已经在我的一些程序中安装了FTP(文件传输)和SMTP(邮件)支持,并取得了成功.我也使用了HTTP(Get),然后解析了一些字符串,也取得了成功.但是,就是这样!
现在我必须连接到https(安全)URL并使用ASMX服务来发送和接收XML文件.该文件没问题,已经过测试.
但是..我几乎不知道如何使用Delphi 7实现这种连接.我怀疑SOAP(简单对象访问协议)和可疑离子是从这个例子中引出的,在这里它创建对象"out out稀薄的空气"没有视觉课,但我不确定!
书面示例在C#中:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
namespace SendaStgrXML
{
public partial class AAmain : Form
{
public AAmain()
{
InitializeComponent();
}
private string FileLoc = null;
private void AAmain_Load(object sender, EventArgs e)
{
}
private void btnSend_Click(object sender, EventArgs e)
{
Stream strm;
try
{
// Test:
string url = @"https://securep.rsk.is/stadgreidsla/stadgreidslaws/thjonusta.asmx";
// Life:
//string url = @"https://secure.rsk.is/stadgreidsla/stadgreidslaws/thjonusta.asmx";
//proxyStadgreidslaWSE.Stadgreidsla stadgr = …Run Code Online (Sandbox Code Playgroud) 我试图将一些vb.net转换为C#,但我一直在收到错误.目前,我收到以下错误:
The name 'Strings' does not exist in the current context
Run Code Online (Sandbox Code Playgroud)
问题在于:
strUser = Strings.LCase(Strings.Trim(strUserInitials[strUserInitials.GetUpperBound(0)])).ToString();
Run Code Online (Sandbox Code Playgroud)
任何人都知道为什么会这样吗?
我有以下命名空间集:
using System;
using System.Web;
using System.Web.Services;
using System.Web.Script;
using System.Web.Script.Services;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
Run Code Online (Sandbox Code Playgroud)
我正在开发一个webservice(asmx文件).
从ASMX服务返回的对象在Silverlight应用程序中使用.类具有方法,但ASMX WebMethod的结果不显示对象的方法.
这是我的课
public class Dog
{
public string Name{get;set;}
public void Bark();
}
Run Code Online (Sandbox Code Playgroud)
这是WebMethod
[WebMethod]
public List<Dog> Findlabrador()
{
blah blah blah
return list_of_labrador;
}
Run Code Online (Sandbox Code Playgroud)
银光代码
void LabradorFetchCompleted(object sender, LabradorFetchCompletedEventArgs e)
{
var list_of_labrador = e.Result;
foreach(var labradorDog in list_of_labrador)
{
labradorDog.Bark();
//** WTH my labrador can't BARK** Bark method is not shown in intellisense there is compilation error if i explicitly specify
}
}
Run Code Online (Sandbox Code Playgroud)
好吧,嗯,让我说出你的话.以下是重现问题的步骤
创建一个Silverlight应用程序项目(让VS创建网站来托管应用程序)
创建一个Silverlight类库,在其中创建Dog类
将Silverlight类库编译为assembly(Dog.dll)
将Dog.dllsilverlight程序集的引用添加到silverlight应用程序项目中
将WebService应用程序添加到项目中(DogService.asmx注意asmx …
我创建了一个包含枚举的Web服务,其值如下所示
public enum DesignChoice
{
DesignerChoice = 1,
CustomerChoice = 2,
AdditionalDesign=3,
}
Run Code Online (Sandbox Code Playgroud)
当我添加对客户端网站的引用时,枚举值会更改,如下面的代码所示:
(int)DesignChoice.AdditionalDesign 返回2,但我期待它是3.
我已经尝试了序列化属性[System.Xml.Serialization.XmlTypeAttribute()],但没有运气.
该服务的WSDL描述了枚举如下:
<s:simpleType name="DesignChoice">
<s:restriction base="s:string">
<s:enumeration value="DesignerChoice" />
<s:enumeration value="CustomerChoice" />
<s:enumeration value="AdditionalDesign" />
</s:restriction>
</s:simpleType>
Run Code Online (Sandbox Code Playgroud)
当我在VS中的类名上按F12时,它显示了从元数据生成的以下代码:
public enum DesignChoice
{
DesignerChoice = 0,
CustomerChoice = 1,
AdditionalDesign = 2,
}
Run Code Online (Sandbox Code Playgroud)
我使用的是Visual Studio 2005和.NET 2.0.
所以我在Visual Studio 2010中创建了一个Web服务.要将它部署到IIS Web服务器上,我将service.asmx,web.config和bin复制到服务器(wwwroot文件夹).一切正常.
我的问题是从web.config读取一个简单的字符串.我的代码是:
在一种方法中,我有:
string from = System.Configuration.ConfigurationManager.AppSettings["folder_new"];
Run Code Online (Sandbox Code Playgroud)
在web.config文件中,我有:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="folder_new" value="C:\images\new" />
</appSettings>
<...other stuff etc...>
</configuration>
Run Code Online (Sandbox Code Playgroud)
我从"从"的位置读入.如果我改成它
string from = @"C:\images\new";
Run Code Online (Sandbox Code Playgroud)
它完美地运作.
这真让我抓狂.
如果我要更改方法名称和参数的大小写,这是否会对使用asmx或WCF Web服务的客户产生负面影响?
public string getSTRING(int INPUT)
{
return INPUT.ToString();
}
Run Code Online (Sandbox Code Playgroud)
至....
public string GetString(int input)
{
return input.ToString();
}
Run Code Online (Sandbox Code Playgroud)
客户是否需要重新生成其代理对象以使用更改的方法?
我有这个方法的asmx webserice
[WebMethod]
double GetBookPrice(int bookID)
{
//instantiates a DiscountService,DeliveryService and a couple of other services
//uses various methods of these services to calculate the price
//e.g. DiscountService.CalculateDiscount(book)
}
Run Code Online (Sandbox Code Playgroud)
有4种服务是此方法的依赖项.
现在如何测试这种方法?我需要注入这些依赖项?或者我应该这样做?客户端只是发送一个int来检查价格.
谢谢
C#WebMethod是否可以接受与其客户端发送的不同的参数名称?
例如,给定客户端发送此消息:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetStatus xmlns="http://example.com/">
<Arg1>5</Arg1>
<Arg2>3</Arg2>
</GetStatus>
</soap:Body>
</soap:Envelope>
Run Code Online (Sandbox Code Playgroud)
是否可以重写现有的WebMethod以适应不同的参数名称?像这样的东西?
[WebMethod]
public string GetStatus(
[MessageParameter(Name = "Arg1")] string orderId,
[MessageParameter(Name = "Arg2")] string typeId)
Run Code Online (Sandbox Code Playgroud) asmx ×10
c# ×6
.net ×3
web-services ×3
asp.net ×2
jquery ×2
.net-2.0 ×1
.net-3.5 ×1
class ×1
delphi ×1
enums ×1
json ×1
parameters ×1
silverlight ×1
vb.net-to-c# ×1
wcf ×1
web-config ×1
webmethod ×1
xml ×1