访问者:获取和设置不同的数据类型 [英] Accessors: Get and Set distinct data types

查看:142
本文介绍了访问者:获取和设置不同的数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个问题的背景:我正在使用SOAP webservices,并且我遇到日期类型的一些问题。我没有开发网络服务,因此我完全不了解它们。我有一个webservice有两种方法: getCountry setCountry 。其中一个必填字段是 beginDateField 。问题是,当我调用 getCountry 方法时,我会收到XML 中的错误 - 就是这样。我认为它可能与日期字段有关,并解决问题,我在解决方案资源管理器中的服务引用下访问了 reference.cs 文件,并在任何地方更改有 DateTime string :当我想从webservice获取国家时,它的工作效果很好。会发生什么,当我想调用 setCountry 方法时,C#要求我一个字符串,但WebService期待一个 DateTime



现在具体问题 - 我有一点代码:

  private string beginDateField; 

(...)

public string beginDate {
get {
return this.beginDateField;
}
set {
this.beginDateField = value;
}
}

我需要设置 beginDateField 作为 DateTime ,我已经尝试过:

  set {
this.beginDateField = Convert.ToDateTime(value);
}

但我收到错误:





任何想法?



感谢



(编辑)



这是原始错误,这是我首先改变了 reference.cs 文件的错误。





错误是葡萄牙语和它说 XML文档中有一个错误(1,1274)

解决方案

看起来像由于您收到的System.FormatException,beginDate属性的value里面的字符串的格式不正确。



有关FormatException的更多信息:
http://www.dotnetperls.com/formatexception



以下是有关DateTime的字符串格式的更多信息:
http://www.csharp-examples.net/string-format-datetime/



希望这有助于解决您的问题。如果没有,请回到我:)


this is some background to the problem: I'm working with SOAP webservices and I'm getting some issues with the date types. I haven't developed the webservices and for that reason I can't understand them completely. I have a webservice with two methods: getCountry and setCountry. One of the mandatory fields is the beginDateField. The problem is, when I call the getCountry method, I get an error in XML - just this. I figured it could have something to do with the date fields and to solve the problem, I accessed the reference.cs file under the service reference in the solution explorer and changed wherever it had DateTime to string: and it works perfectly when I want to get the countries from the webservice. What happens is, when I want to call the setCountry method, C# asks me for a string but the WebService is expecting a DateTime.

Now the specific problem - I've got this bit of code:

    private string beginDateField;

    (...)

    public string beginDate {
        get {
            return this.beginDateField;
        }
        set {
            this.beginDateField = value;
        }
    }

I need to set the beginDateField as a DateTime and I have tried this:

    set {
        this.beginDateField = Convert.ToDateTime(value);
    }

but I get an error:

Any ideas?

Thanks

(EDIT)

Here's the original error, the one which made me change the reference.cs file in the first place.

The error is in Portuguese and it says There is an error in the XML document (1, 1274)

解决方案

It looks like the format of the string is held in the 'value' inside the beginDate property is not in the correct format due to the System.FormatException you are getting.

More information on FormatException: http://www.dotnetperls.com/formatexception

May you post the exact value which is being passed into the set method inside the beginDate property please.

Here is more information on string formats for DateTime: http://www.csharp-examples.net/string-format-datetime/

Hope this helps towards solving your problem. If not please get back to me :)

这篇关于访问者:获取和设置不同的数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆