开发者

Web Service types not updating

I have encountered a strange issue. When I update one of my websites to a web service by

  1. Updating it or
  2. Removal of the service and readding it altogether

The intellisense still reports that the type, in this case Document_Type3 is still the same type of an object generated by the service. I can set my object type to `Document_Type3'. I build the project, no issues.

Web Service types not updating

However, when I run the project, I get a compiler error saying that that my object which is Document_Type3 doesn't contain the Order.

Compiler Error Message: CS0117: 'DynamicsNAV.Document_Type3' does not contain a definition for 'Order'

Source Error:

Line 376:                comment.Date = DateTime.Now;
Line 377:                comment.DateSpecified = true;
Line 378:                comment.Document_Type = Document_Type3.Order;  <-- right here.
Line 379:                comment.Document_TypeSpecified = true;
Line 380:                comment.Line_No = i * 1000;

The hell it doesn't. I can see it right there.

  <xsd:simpleType name="Document_Type">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="Quote" />
      <xsd:enumeration value="Order" />
    </xsd:restriction>
  </xsd:simpleType>

I can set it fine, compile it fine -- but I can't run it.

I nuked my temporary files in

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files

thinking that it perhaps has cached these dynamically generated objects. I rebuilt the project and watched the website reappear, along with the objects, in the temporary directory.

When I run it -- same thing -- no compiler error until it actually loads in the browser. An important issue to note is that these services are being returned by Dynamics NAV, and types that have the same name, such as Document_Type, will be appended with a number 开发者_C百科on the end. In the code, again, Document_Type3 contains Order and Quote.

What the heck is going on?


This is definitely a bug within Visual Studio/Web Service Code Generation. Here's my explanation of what I believe is happening and how to fix it work around it.

In NAV (or any other web services) where there is a non-distinctly named type of object, in this case "Document_Type", apparently the build is getting out of order when it is compiled. For example, I might have three separate WSDL objects that all define a document type. e.g.

CustomerSale.wsdl
WebSale.wsdl
VendorSale.wsdl

When Visual Studio code gens the object, it goes through each of my WSDL objects, finds the Document_Type, and enumerates accordingly. e.g.

CustomerSale.Document_Type -> Document_Type1
WebSale.Document_Type -> Document_Type2
VendorSale.Document_Type -> Document_Type3

However, when the web compiles the objects, the objects get out of order. e.g.

CustomerSale.Document_Type -> Document_Type1
WebSale.Document_Type -> Document_Type3
VendorSale.Document_Type -> Document_Type2

I'm not sure if this depends on the alphabetical order of the objects or some other variable, but it definately happens.

I can't see a rhyme or reason these would be getting out of sync, but the simple solution (in my case) was to simply delete the WSDL object causing the confusion to the compiler. I didn't need it anyway.

To find, at runtime, which object was causing the compiler confusion, I reflected the type:

Response.Write(WebSale.Document_Type.GetType().ToString);
Response.End();

I then went to the definition, in this case Document_Type2 and saw that it was definitely not the same object. I then removed the object from my web services, and web.config -- then I recompiled. My Web object immediately turned into Document_Type2! This cleared everything up and allowed the site to compile in the actual browser. They were now in sync.

However, I understand that not everyone has objects they can remove, as they might actually be using those objects. Another work around would be to dynamically set the object via reflection. Instead of binding your object type to `Document_Type2' you could instead reflect the type and cast as necessary. e.g.

//Document type will throw error at run time.
//comment.Document_Type = DynamicsNAV.Document_Type3.Order; <-- removed.
// I don't care what the name of the object is,
// I know that it contains Order.   
var prop = comment.GetType().GetProperty("Document_Type");
prop.SetValue(comment, Enum.Parse(prop.PropertyType, "Order"), null);

I hope this solution helps others who are experiencing the same issue!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜